Computer vision can be used to automate supervision and generate action appropriate action trigger if the event is predicted from the image of interest. For example a car moving on the road can be easily identified by a camera as make of the car, type, colour, number plates etc.
The Cars dataset contains 16,185 images of 196 classes of cars. The data is split into 8,144 training images and 8,041 testing images, where each class has been split roughly in a 50-50 split. Classes are typically at the level of Make, Model, Year, e.g. 2012 Tesla Model S or 2012 BMW M3 coupe. Data description: ‣ Train Images: Consists of real images of cars as per the make and year of the car. ‣ Test Images: Consists of real images of cars as per the make and year of the car. ‣ Train Annotation: Consists of bounding box region for training images. ‣ Test Annotation: Consists of bounding box region for testing images.
Dataset: https://drive.google.com/drive/folders/1y6JWx2CpsOuka00uePe72jNgr7F9sK45?usp=sharing Original dataset link for your reference only: https://www.kaggle.com/jutrera/stanford-car-dataset-by-classes-folder Reference: 3D Object Representations for Fine-Grained Categorisation, Jonathan Krause, Michael Stark, Jia Deng, Li Fei-Fei 4th IEEE Workshop on 3D Representation and Recognition, at ICCV 2013 (3dRR-13). Sydney, Australia. Dec. 8, 2013.
from google.colab import drive
drive.mount("/content.gdrive")
Mounted at /content.gdrive
# Initialize the random number generator
import random
random.seed(0)
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import tensorflow as tf
import os
%matplotlib inline
import cv2
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.models import Sequential
from tensorflow.keras import regularizers, optimizers
from tensorflow.keras.models import Model,load_model
from sklearn import preprocessing
from tensorflow.keras.layers import Input,InputLayer,Dense, Dropout, BatchNormalization,Flatten,Activation,Conv2D,MaxPool2D,GlobalMaxPool2D
from tensorflow.keras.callbacks import ModelCheckpoint,EarlyStopping
from tensorflow.keras.optimizers import Adam
from sklearn.metrics import accuracy_score, r2_score,classification_report,confusion_matrix, precision_score, recall_score, f1_score, precision_recall_curve, auc
# used to supress display of warnings
import warnings
warnings.filterwarnings("ignore")
from sklearn.metrics import precision_recall_curve,accuracy_score,f1_score,precision_score,recall_score
%tensorflow_version 2.x
tf.__version__
'2.6.0'
project_path='/content.gdrive/MyDrive'
path = os.getcwd()
print(path)
#Changing the directory
os.chdir(project_path)
print(os.getcwd())
/content /content.gdrive/MyDrive
path = os.getcwd()
print(path)
/Users/Z005BWR/Downloads/GL
pathToTrainData ='Dataset/Car Images/Train Images'
#Importing the training data set
cars_train_data = pd.DataFrame(columns=['imageName','imagePath','class','height','width'])
for dirname, _, filenames in os.walk(pathToTrainData):
for filename in filenames:
path = os.path.join(dirname, filename)
img_name = os.path.split(path)[1]
if img_name!='.DS_Store':
img = cv2.imread(path)
height, width, channel = img.shape
class_label = dirname.split('/')[-1]
cars_train_data = cars_train_data.append({'imageName':img_name,'imagePath':path , 'class':class_label,'height':height,'width':width}, ignore_index = True)
cars_train_data.to_csv(r'Dataset/cars_train_data.csv', index=False)
cars_train_data
| imageName | imagePath | class | height | width | |
|---|---|---|---|---|---|
| 0 | 06796.jpg | Dataset/Car Images/Train Images/Dodge Dakota C... | Dodge Dakota Crew Cab 2010 | 312 | 416 |
| 1 | 04157.jpg | Dataset/Car Images/Train Images/Dodge Dakota C... | Dodge Dakota Crew Cab 2010 | 194 | 259 |
| 2 | 00682.jpg | Dataset/Car Images/Train Images/Dodge Dakota C... | Dodge Dakota Crew Cab 2010 | 240 | 320 |
| 3 | 07660.jpg | Dataset/Car Images/Train Images/Dodge Dakota C... | Dodge Dakota Crew Cab 2010 | 768 | 1024 |
| 4 | 00483.jpg | Dataset/Car Images/Train Images/Dodge Dakota C... | Dodge Dakota Crew Cab 2010 | 360 | 640 |
| ... | ... | ... | ... | ... | ... |
| 8139 | 03541.jpg | Dataset/Car Images/Train Images/Chevrolet Corv... | Chevrolet Corvette ZR1 2012 | 334 | 500 |
| 8140 | 07479.jpg | Dataset/Car Images/Train Images/Chevrolet Corv... | Chevrolet Corvette ZR1 2012 | 480 | 640 |
| 8141 | 07876.jpg | Dataset/Car Images/Train Images/Chevrolet Corv... | Chevrolet Corvette ZR1 2012 | 183 | 300 |
| 8142 | 07484.jpg | Dataset/Car Images/Train Images/Chevrolet Corv... | Chevrolet Corvette ZR1 2012 | 183 | 276 |
| 8143 | 03185.jpg | Dataset/Car Images/Train Images/Chevrolet Corv... | Chevrolet Corvette ZR1 2012 | 3240 | 4320 |
8144 rows × 5 columns
cars_train_data = pd.read_csv('Dataset/cars_train_data.csv')
#Removing parent directory, if any
cars_train_data = cars_train_data[cars_train_data['class'] != 'Train Images']
cars_train_data
| imageName | imagePath | class | height | width | |
|---|---|---|---|---|---|
| 0 | 06796.jpg | Dataset/Car Images/Train Images/Dodge Dakota C... | Dodge Dakota Crew Cab 2010 | 312 | 416 |
| 1 | 04157.jpg | Dataset/Car Images/Train Images/Dodge Dakota C... | Dodge Dakota Crew Cab 2010 | 194 | 259 |
| 2 | 00682.jpg | Dataset/Car Images/Train Images/Dodge Dakota C... | Dodge Dakota Crew Cab 2010 | 240 | 320 |
| 3 | 07660.jpg | Dataset/Car Images/Train Images/Dodge Dakota C... | Dodge Dakota Crew Cab 2010 | 768 | 1024 |
| 4 | 00483.jpg | Dataset/Car Images/Train Images/Dodge Dakota C... | Dodge Dakota Crew Cab 2010 | 360 | 640 |
| ... | ... | ... | ... | ... | ... |
| 8139 | 03541.jpg | Dataset/Car Images/Train Images/Chevrolet Corv... | Chevrolet Corvette ZR1 2012 | 334 | 500 |
| 8140 | 07479.jpg | Dataset/Car Images/Train Images/Chevrolet Corv... | Chevrolet Corvette ZR1 2012 | 480 | 640 |
| 8141 | 07876.jpg | Dataset/Car Images/Train Images/Chevrolet Corv... | Chevrolet Corvette ZR1 2012 | 183 | 300 |
| 8142 | 07484.jpg | Dataset/Car Images/Train Images/Chevrolet Corv... | Chevrolet Corvette ZR1 2012 | 183 | 276 |
| 8143 | 03185.jpg | Dataset/Car Images/Train Images/Chevrolet Corv... | Chevrolet Corvette ZR1 2012 | 3240 | 4320 |
8144 rows × 5 columns
cars_train_data.info()
<class 'pandas.core.frame.DataFrame'> Int64Index: 8144 entries, 0 to 8143 Data columns (total 5 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 imageName 8144 non-null object 1 imagePath 8144 non-null object 2 class 8144 non-null object 3 height 8144 non-null int64 4 width 8144 non-null int64 dtypes: int64(2), object(3) memory usage: 381.8+ KB
Visualizing Training images
image_1 = cars_train_data.iloc[0,:].imagePath
image_1
'Dataset/Car Images/Train Images/Dodge Dakota Crew Cab 2010/06796.jpg'
#Function to Visualize the images
def load_car_image(path):
img = cv2.imread(path)
print(img.shape)
# OpenCV loads images with color channels in BGR order. So we need to reverse them
return img[...,::-1]
plt.imshow(load_car_image(image_1))
(312, 416, 3)
<matplotlib.image.AxesImage at 0x7fa630b34f40>
#Let us check its corresponding class
cars_train_data.iloc[0,:]['class']
'Dodge Dakota Crew Cab 2010'
plt.imshow(load_car_image(cars_train_data.iloc[1,:].imagePath))
(194, 259, 3)
<matplotlib.image.AxesImage at 0x7fa6991634f0>
#Let us check its corresponding class
cars_train_data.iloc[1,:]['class']
'Dodge Dakota Crew Cab 2010'
plt.imshow(load_car_image(cars_train_data.iloc[8000,:].imagePath))
cars_train_data.iloc[8000,:]['class']
(480, 640, 3)
'GMC Savana Van 2012'
Total classes in Training Data set
cars_train_data['class'].value_counts()
GMC Savana Van 2012 68
Chrysler 300 SRT-8 2010 49
Mercedes-Benz 300-Class Convertible 1993 48
Mitsubishi Lancer Sedan 2012 48
Chevrolet Corvette ZR1 2012 47
..
Rolls-Royce Phantom Drophead Coupe Convertible 2012 31
Chevrolet Express Cargo Van 2007 30
Maybach Landaulet Convertible 2012 29
FIAT 500 Abarth 2012 28
Hyundai Accent Sedan 2012 24
Name: class, Length: 196, dtype: int64
unique, counts = np.unique(cars_train_data['class'], return_counts=True)
unique, counts
(array(['AM General Hummer SUV 2000', 'Acura Integra Type R 2001',
'Acura RL Sedan 2012', 'Acura TL Sedan 2012',
'Acura TL Type-S 2008', 'Acura TSX Sedan 2012',
'Acura ZDX Hatchback 2012',
'Aston Martin V8 Vantage Convertible 2012',
'Aston Martin V8 Vantage Coupe 2012',
'Aston Martin Virage Convertible 2012',
'Aston Martin Virage Coupe 2012', 'Audi 100 Sedan 1994',
'Audi 100 Wagon 1994', 'Audi A5 Coupe 2012', 'Audi R8 Coupe 2012',
'Audi RS 4 Convertible 2008', 'Audi S4 Sedan 2007',
'Audi S4 Sedan 2012', 'Audi S5 Convertible 2012',
'Audi S5 Coupe 2012', 'Audi S6 Sedan 2011',
'Audi TT Hatchback 2011', 'Audi TT RS Coupe 2012',
'Audi TTS Coupe 2012', 'Audi V8 Sedan 1994',
'BMW 1 Series Convertible 2012', 'BMW 1 Series Coupe 2012',
'BMW 3 Series Sedan 2012', 'BMW 3 Series Wagon 2012',
'BMW 6 Series Convertible 2007', 'BMW ActiveHybrid 5 Sedan 2012',
'BMW M3 Coupe 2012', 'BMW M5 Sedan 2010',
'BMW M6 Convertible 2010', 'BMW X3 SUV 2012', 'BMW X5 SUV 2007',
'BMW X6 SUV 2012', 'BMW Z4 Convertible 2012',
'Bentley Arnage Sedan 2009',
'Bentley Continental Flying Spur Sedan 2007',
'Bentley Continental GT Coupe 2007',
'Bentley Continental GT Coupe 2012',
'Bentley Continental Supersports Conv. Convertible 2012',
'Bentley Mulsanne Sedan 2011',
'Bugatti Veyron 16.4 Convertible 2009',
'Bugatti Veyron 16.4 Coupe 2009', 'Buick Enclave SUV 2012',
'Buick Rainier SUV 2007', 'Buick Regal GS 2012',
'Buick Verano Sedan 2012', 'Cadillac CTS-V Sedan 2012',
'Cadillac Escalade EXT Crew Cab 2007', 'Cadillac SRX SUV 2012',
'Chevrolet Avalanche Crew Cab 2012',
'Chevrolet Camaro Convertible 2012', 'Chevrolet Cobalt SS 2010',
'Chevrolet Corvette Convertible 2012',
'Chevrolet Corvette Ron Fellows Edition Z06 2007',
'Chevrolet Corvette ZR1 2012', 'Chevrolet Express Cargo Van 2007',
'Chevrolet Express Van 2007', 'Chevrolet HHR SS 2010',
'Chevrolet Impala Sedan 2007',
'Chevrolet Malibu Hybrid Sedan 2010',
'Chevrolet Malibu Sedan 2007', 'Chevrolet Monte Carlo Coupe 2007',
'Chevrolet Silverado 1500 Classic Extended Cab 2007',
'Chevrolet Silverado 1500 Extended Cab 2012',
'Chevrolet Silverado 1500 Hybrid Crew Cab 2012',
'Chevrolet Silverado 1500 Regular Cab 2012',
'Chevrolet Silverado 2500HD Regular Cab 2012',
'Chevrolet Sonic Sedan 2012', 'Chevrolet Tahoe Hybrid SUV 2012',
'Chevrolet TrailBlazer SS 2009', 'Chevrolet Traverse SUV 2012',
'Chrysler 300 SRT-8 2010', 'Chrysler Aspen SUV 2009',
'Chrysler Crossfire Convertible 2008',
'Chrysler PT Cruiser Convertible 2008',
'Chrysler Sebring Convertible 2010',
'Chrysler Town and Country Minivan 2012',
'Daewoo Nubira Wagon 2002', 'Dodge Caliber Wagon 2007',
'Dodge Caliber Wagon 2012', 'Dodge Caravan Minivan 1997',
'Dodge Challenger SRT8 2011', 'Dodge Charger SRT-8 2009',
'Dodge Charger Sedan 2012', 'Dodge Dakota Club Cab 2007',
'Dodge Dakota Crew Cab 2010', 'Dodge Durango SUV 2007',
'Dodge Durango SUV 2012', 'Dodge Journey SUV 2012',
'Dodge Magnum Wagon 2008', 'Dodge Ram Pickup 3500 Crew Cab 2010',
'Dodge Ram Pickup 3500 Quad Cab 2009',
'Dodge Sprinter Cargo Van 2009', 'Eagle Talon Hatchback 1998',
'FIAT 500 Abarth 2012', 'FIAT 500 Convertible 2012',
'Ferrari 458 Italia Convertible 2012',
'Ferrari 458 Italia Coupe 2012',
'Ferrari California Convertible 2012', 'Ferrari FF Coupe 2012',
'Fisker Karma Sedan 2012', 'Ford E-Series Wagon Van 2012',
'Ford Edge SUV 2012', 'Ford Expedition EL SUV 2009',
'Ford F-150 Regular Cab 2007', 'Ford F-150 Regular Cab 2012',
'Ford F-450 Super Duty Crew Cab 2012', 'Ford Fiesta Sedan 2012',
'Ford Focus Sedan 2007', 'Ford Freestar Minivan 2007',
'Ford GT Coupe 2006', 'Ford Mustang Convertible 2007',
'Ford Ranger SuperCab 2011', 'GMC Acadia SUV 2012',
'GMC Canyon Extended Cab 2012', 'GMC Savana Van 2012',
'GMC Terrain SUV 2012', 'GMC Yukon Hybrid SUV 2012',
'Geo Metro Convertible 1993', 'HUMMER H2 SUT Crew Cab 2009',
'HUMMER H3T Crew Cab 2010', 'Honda Accord Coupe 2012',
'Honda Accord Sedan 2012', 'Honda Odyssey Minivan 2007',
'Honda Odyssey Minivan 2012', 'Hyundai Accent Sedan 2012',
'Hyundai Azera Sedan 2012', 'Hyundai Elantra Sedan 2007',
'Hyundai Elantra Touring Hatchback 2012',
'Hyundai Genesis Sedan 2012', 'Hyundai Santa Fe SUV 2012',
'Hyundai Sonata Hybrid Sedan 2012', 'Hyundai Sonata Sedan 2012',
'Hyundai Tucson SUV 2012', 'Hyundai Veloster Hatchback 2012',
'Hyundai Veracruz SUV 2012', 'Infiniti G Coupe IPL 2012',
'Infiniti QX56 SUV 2011', 'Isuzu Ascender SUV 2008',
'Jaguar XK XKR 2012', 'Jeep Compass SUV 2012',
'Jeep Grand Cherokee SUV 2012', 'Jeep Liberty SUV 2012',
'Jeep Patriot SUV 2012', 'Jeep Wrangler SUV 2012',
'Lamborghini Aventador Coupe 2012',
'Lamborghini Diablo Coupe 2001',
'Lamborghini Gallardo LP 570-4 Superleggera 2012',
'Lamborghini Reventon Coupe 2008', 'Land Rover LR2 SUV 2012',
'Land Rover Range Rover SUV 2012', 'Lincoln Town Car Sedan 2011',
'MINI Cooper Roadster Convertible 2012',
'Maybach Landaulet Convertible 2012', 'Mazda Tribute SUV 2011',
'McLaren MP4-12C Coupe 2012',
'Mercedes-Benz 300-Class Convertible 1993',
'Mercedes-Benz C-Class Sedan 2012',
'Mercedes-Benz E-Class Sedan 2012',
'Mercedes-Benz S-Class Sedan 2012',
'Mercedes-Benz SL-Class Coupe 2009',
'Mercedes-Benz Sprinter Van 2012', 'Mitsubishi Lancer Sedan 2012',
'Nissan 240SX Coupe 1998', 'Nissan Juke Hatchback 2012',
'Nissan Leaf Hatchback 2012', 'Nissan NV Passenger Van 2012',
'Plymouth Neon Coupe 1999', 'Porsche Panamera Sedan 2012',
'Ram C-V Cargo Van Minivan 2012', 'Rolls-Royce Ghost Sedan 2012',
'Rolls-Royce Phantom Drophead Coupe Convertible 2012',
'Rolls-Royce Phantom Sedan 2012', 'Scion xD Hatchback 2012',
'Spyker C8 Convertible 2009', 'Spyker C8 Coupe 2009',
'Suzuki Aerio Sedan 2007', 'Suzuki Kizashi Sedan 2012',
'Suzuki SX4 Hatchback 2012', 'Suzuki SX4 Sedan 2012',
'Tesla Model S Sedan 2012', 'Toyota 4Runner SUV 2012',
'Toyota Camry Sedan 2012', 'Toyota Corolla Sedan 2012',
'Toyota Sequoia SUV 2012', 'Volkswagen Beetle Hatchback 2012',
'Volkswagen Golf Hatchback 1991', 'Volkswagen Golf Hatchback 2012',
'Volvo 240 Sedan 1993', 'Volvo C30 Hatchback 2012',
'Volvo XC90 SUV 2007', 'smart fortwo Convertible 2012'],
dtype=object),
array([45, 45, 32, 43, 42, 41, 39, 45, 41, 33, 38, 41, 43, 41, 43, 37, 45,
40, 42, 43, 46, 41, 40, 43, 44, 36, 41, 43, 42, 44, 34, 45, 41, 41,
39, 42, 42, 41, 39, 45, 46, 35, 37, 36, 33, 44, 42, 43, 35, 38, 43,
45, 41, 45, 45, 42, 40, 38, 47, 30, 35, 37, 43, 39, 45, 45, 43, 44,
40, 44, 38, 44, 37, 40, 44, 49, 44, 43, 45, 41, 38, 45, 42, 41, 44,
39, 42, 41, 39, 41, 46, 44, 44, 40, 43, 44, 40, 46, 28, 34, 40, 43,
39, 42, 44, 38, 43, 45, 45, 43, 42, 43, 45, 44, 46, 45, 42, 45, 40,
68, 42, 43, 45, 44, 39, 39, 39, 41, 42, 24, 42, 42, 43, 44, 42, 34,
40, 44, 41, 42, 34, 33, 40, 47, 43, 45, 45, 44, 43, 44, 45, 36, 36,
43, 43, 39, 37, 29, 36, 44, 48, 46, 44, 45, 37, 41, 48, 46, 44, 42,
39, 44, 44, 41, 39, 31, 44, 42, 45, 43, 38, 46, 42, 41, 39, 41, 44,
44, 39, 43, 46, 43, 46, 42, 43, 40]))
We can see that training images has 8144 images. and has 196 classes. Let us create the testing data set now.
pathToTestData ='Dataset/Car Images/Test Images'
#Importing the testing data set
cars_test_data = pd.DataFrame(columns=['imageName','imagePath','class','height','width'])
for dirname, _, filenames in os.walk(pathToTestData):
for filename in filenames:
path = os.path.join(dirname, filename)
img_name = os.path.split(path)[1]
if img_name!='.DS_Store':
img = cv2.imread(path)
height, width, channel = img.shape
class_label = dirname.split('/')[-1]
cars_test_data = cars_test_data.append({'imageName':img_name,'imagePath':path , 'class':class_label,'height':height,'width':width}, ignore_index = True)
cars_test_data = cars_test_data[cars_test_data['class'] != 'Test Images']
cars_test_data.to_csv(r'Dataset/cars_test_data.csv', index=False)
cars_test_data
| imageName | imagePath | class | height | width | |
|---|---|---|---|---|---|
| 0 | 00318.jpg | Dataset/Car Images/Test Images/Dodge Dakota Cr... | Dodge Dakota Crew Cab 2010 | 360 | 480 |
| 1 | 03773.jpg | Dataset/Car Images/Test Images/Dodge Dakota Cr... | Dodge Dakota Crew Cab 2010 | 194 | 259 |
| 2 | 01206.jpg | Dataset/Car Images/Test Images/Dodge Dakota Cr... | Dodge Dakota Crew Cab 2010 | 225 | 300 |
| 3 | 08018.jpg | Dataset/Car Images/Test Images/Dodge Dakota Cr... | Dodge Dakota Crew Cab 2010 | 768 | 1024 |
| 4 | 05448.jpg | Dataset/Car Images/Test Images/Dodge Dakota Cr... | Dodge Dakota Crew Cab 2010 | 225 | 300 |
| ... | ... | ... | ... | ... | ... |
| 8036 | 07450.jpg | Dataset/Car Images/Test Images/Chevrolet Corve... | Chevrolet Corvette ZR1 2012 | 221 | 300 |
| 8037 | 07518.jpg | Dataset/Car Images/Test Images/Chevrolet Corve... | Chevrolet Corvette ZR1 2012 | 194 | 259 |
| 8038 | 02893.jpg | Dataset/Car Images/Test Images/Chevrolet Corve... | Chevrolet Corvette ZR1 2012 | 492 | 786 |
| 8039 | 06161.jpg | Dataset/Car Images/Test Images/Chevrolet Corve... | Chevrolet Corvette ZR1 2012 | 194 | 259 |
| 8040 | 07109.jpg | Dataset/Car Images/Test Images/Chevrolet Corve... | Chevrolet Corvette ZR1 2012 | 853 | 1280 |
8041 rows × 5 columns
cars_test_data = pd.read_csv('Dataset/cars_test_data.csv')
cars_test_data
| imageName | imagePath | class | height | width | |
|---|---|---|---|---|---|
| 0 | 00318.jpg | Dataset/Car Images/Test Images/Dodge Dakota Cr... | Dodge Dakota Crew Cab 2010 | 360 | 480 |
| 1 | 03773.jpg | Dataset/Car Images/Test Images/Dodge Dakota Cr... | Dodge Dakota Crew Cab 2010 | 194 | 259 |
| 2 | 01206.jpg | Dataset/Car Images/Test Images/Dodge Dakota Cr... | Dodge Dakota Crew Cab 2010 | 225 | 300 |
| 3 | 08018.jpg | Dataset/Car Images/Test Images/Dodge Dakota Cr... | Dodge Dakota Crew Cab 2010 | 768 | 1024 |
| 4 | 05448.jpg | Dataset/Car Images/Test Images/Dodge Dakota Cr... | Dodge Dakota Crew Cab 2010 | 225 | 300 |
| ... | ... | ... | ... | ... | ... |
| 8036 | 07450.jpg | Dataset/Car Images/Test Images/Chevrolet Corve... | Chevrolet Corvette ZR1 2012 | 221 | 300 |
| 8037 | 07518.jpg | Dataset/Car Images/Test Images/Chevrolet Corve... | Chevrolet Corvette ZR1 2012 | 194 | 259 |
| 8038 | 02893.jpg | Dataset/Car Images/Test Images/Chevrolet Corve... | Chevrolet Corvette ZR1 2012 | 492 | 786 |
| 8039 | 06161.jpg | Dataset/Car Images/Test Images/Chevrolet Corve... | Chevrolet Corvette ZR1 2012 | 194 | 259 |
| 8040 | 07109.jpg | Dataset/Car Images/Test Images/Chevrolet Corve... | Chevrolet Corvette ZR1 2012 | 853 | 1280 |
8041 rows × 5 columns
We can see that testing images has 8041 images.
We will sort, test and train images by image name.
cars_train_data.sort_values(['imageName'],axis=0,ascending=[True],inplace=True)
cars_test_data.sort_values(['imageName'],axis=0,ascending=[True],inplace=True)
#Renaming imageName to match to Annotations Data Set
cars_train_data.rename(columns = {'imageName': 'Image Name'},inplace = True)
cars_test_data.rename(columns = {'imageName': 'Image Name'},inplace = True)
cars_train_data
| Image Name | imagePath | class | height | width | |
|---|---|---|---|---|---|
| 4114 | 00001.jpg | Dataset/Car Images/Train Images/Audi TTS Coupe... | Audi TTS Coupe 2012 | 400 | 600 |
| 6607 | 00002.jpg | Dataset/Car Images/Train Images/Acura TL Sedan... | Acura TL Sedan 2012 | 675 | 900 |
| 1760 | 00003.jpg | Dataset/Car Images/Train Images/Dodge Dakota C... | Dodge Dakota Club Cab 2007 | 480 | 640 |
| 1596 | 00004.jpg | Dataset/Car Images/Train Images/Hyundai Sonata... | Hyundai Sonata Hybrid Sedan 2012 | 1386 | 2100 |
| 6564 | 00005.jpg | Dataset/Car Images/Train Images/Ford F-450 Sup... | Ford F-450 Super Duty Crew Cab 2012 | 108 | 144 |
| ... | ... | ... | ... | ... | ... |
| 2973 | 08140.jpg | Dataset/Car Images/Train Images/Chrysler Town ... | Chrysler Town and Country Minivan 2012 | 360 | 424 |
| 5781 | 08141.jpg | Dataset/Car Images/Train Images/smart fortwo C... | smart fortwo Convertible 2012 | 600 | 800 |
| 6804 | 08142.jpg | Dataset/Car Images/Train Images/Mercedes-Benz ... | Mercedes-Benz SL-Class Coupe 2009 | 469 | 750 |
| 6239 | 08143.jpg | Dataset/Car Images/Train Images/Ford GT Coupe ... | Ford GT Coupe 2006 | 1067 | 1600 |
| 2150 | 08144.jpg | Dataset/Car Images/Train Images/Audi 100 Sedan... | Audi 100 Sedan 1994 | 683 | 883 |
8144 rows × 5 columns
cars_test_data
| Image Name | imagePath | class | height | width | |
|---|---|---|---|---|---|
| 4541 | 00001.jpg | Dataset/Car Images/Test Images/Suzuki Aerio Se... | Suzuki Aerio Sedan 2007 | 182 | 276 |
| 3232 | 00002.jpg | Dataset/Car Images/Test Images/Ferrari 458 Ita... | Ferrari 458 Italia Convertible 2012 | 360 | 640 |
| 5276 | 00003.jpg | Dataset/Car Images/Test Images/Jeep Patriot SU... | Jeep Patriot SUV 2012 | 741 | 1024 |
| 2521 | 00004.jpg | Dataset/Car Images/Test Images/Toyota Camry Se... | Toyota Camry Sedan 2012 | 480 | 640 |
| 7832 | 00005.jpg | Dataset/Car Images/Test Images/Tesla Model S S... | Tesla Model S Sedan 2012 | 373 | 600 |
| ... | ... | ... | ... | ... | ... |
| 4350 | 08037.jpg | Dataset/Car Images/Test Images/Chevrolet Sonic... | Chevrolet Sonic Sedan 2012 | 800 | 1200 |
| 3123 | 08038.jpg | Dataset/Car Images/Test Images/Audi V8 Sedan 1... | Audi V8 Sedan 1994 | 480 | 640 |
| 2145 | 08039.jpg | Dataset/Car Images/Test Images/Audi 100 Sedan ... | Audi 100 Sedan 1994 | 303 | 635 |
| 3953 | 08040.jpg | Dataset/Car Images/Test Images/BMW Z4 Converti... | BMW Z4 Convertible 2012 | 427 | 640 |
| 1154 | 08041.jpg | Dataset/Car Images/Test Images/BMW X5 SUV 2007... | BMW X5 SUV 2007 | 426 | 640 |
8041 rows × 5 columns
Let us load the annotations now.
#Loading Training Annotations
pathToAnotations ='Dataset/Annotations'
cars_train_annotations = pd.read_csv(pathToAnotations+'/Train Annotations.csv')
cars_train_annotations
| Image Name | Bounding Box coordinates | Unnamed: 2 | Unnamed: 3 | Unnamed: 4 | Image class | |
|---|---|---|---|---|---|---|
| 0 | 00001.jpg | 39 | 116 | 569 | 375 | 14 |
| 1 | 00002.jpg | 36 | 116 | 868 | 587 | 3 |
| 2 | 00003.jpg | 85 | 109 | 601 | 381 | 91 |
| 3 | 00004.jpg | 621 | 393 | 1484 | 1096 | 134 |
| 4 | 00005.jpg | 14 | 36 | 133 | 99 | 106 |
| ... | ... | ... | ... | ... | ... | ... |
| 8139 | 08140.jpg | 3 | 44 | 423 | 336 | 78 |
| 8140 | 08141.jpg | 138 | 150 | 706 | 523 | 196 |
| 8141 | 08142.jpg | 26 | 246 | 660 | 449 | 163 |
| 8142 | 08143.jpg | 78 | 526 | 1489 | 908 | 112 |
| 8143 | 08144.jpg | 20 | 240 | 862 | 677 | 17 |
8144 rows × 6 columns
We can see that the training annotations have bounding box coordinates of all the 8144 images.
#Loading Testing Annotations
pathToAnotations ='Dataset/Annotations'
cars_test_annotations = pd.read_csv(pathToAnotations+'/Test Annotation.csv')
cars_test_annotations
| Image Name | Bounding Box coordinates | Unnamed: 2 | Unnamed: 3 | Unnamed: 4 | Image class | |
|---|---|---|---|---|---|---|
| 0 | 00001.jpg | 30 | 52 | 246 | 147 | 181 |
| 1 | 00002.jpg | 100 | 19 | 576 | 203 | 103 |
| 2 | 00003.jpg | 51 | 105 | 968 | 659 | 145 |
| 3 | 00004.jpg | 67 | 84 | 581 | 407 | 187 |
| 4 | 00005.jpg | 140 | 151 | 593 | 339 | 185 |
| ... | ... | ... | ... | ... | ... | ... |
| 8036 | 08037.jpg | 49 | 57 | 1169 | 669 | 63 |
| 8037 | 08038.jpg | 23 | 18 | 640 | 459 | 16 |
| 8038 | 08039.jpg | 33 | 27 | 602 | 252 | 17 |
| 8039 | 08040.jpg | 33 | 142 | 521 | 376 | 38 |
| 8040 | 08041.jpg | 77 | 73 | 506 | 380 | 32 |
8041 rows × 6 columns
We can see that the testing annotations have bounding box coordinates of all the 8041 images.
We can see that the annotations dataset has Unamed columns for bounding box coordinates, let us assume it is in the sequence of x1,x2,y1 and y2 and visualize one image to verify it.
Mapping Train and Test images to its annotations and classes now.
car_train_image_details = pd.merge(cars_train_data, cars_train_annotations,
on='Image Name',
how='outer')
car_train_image_details
| Image Name | imagePath | class | height | width | Bounding Box coordinates | Unnamed: 2 | Unnamed: 3 | Unnamed: 4 | Image class | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 00001.jpg | Dataset/Car Images/Train Images/Audi TTS Coupe... | Audi TTS Coupe 2012 | 400 | 600 | 39 | 116 | 569 | 375 | 14 |
| 1 | 00002.jpg | Dataset/Car Images/Train Images/Acura TL Sedan... | Acura TL Sedan 2012 | 675 | 900 | 36 | 116 | 868 | 587 | 3 |
| 2 | 00003.jpg | Dataset/Car Images/Train Images/Dodge Dakota C... | Dodge Dakota Club Cab 2007 | 480 | 640 | 85 | 109 | 601 | 381 | 91 |
| 3 | 00004.jpg | Dataset/Car Images/Train Images/Hyundai Sonata... | Hyundai Sonata Hybrid Sedan 2012 | 1386 | 2100 | 621 | 393 | 1484 | 1096 | 134 |
| 4 | 00005.jpg | Dataset/Car Images/Train Images/Ford F-450 Sup... | Ford F-450 Super Duty Crew Cab 2012 | 108 | 144 | 14 | 36 | 133 | 99 | 106 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 8139 | 08140.jpg | Dataset/Car Images/Train Images/Chrysler Town ... | Chrysler Town and Country Minivan 2012 | 360 | 424 | 3 | 44 | 423 | 336 | 78 |
| 8140 | 08141.jpg | Dataset/Car Images/Train Images/smart fortwo C... | smart fortwo Convertible 2012 | 600 | 800 | 138 | 150 | 706 | 523 | 196 |
| 8141 | 08142.jpg | Dataset/Car Images/Train Images/Mercedes-Benz ... | Mercedes-Benz SL-Class Coupe 2009 | 469 | 750 | 26 | 246 | 660 | 449 | 163 |
| 8142 | 08143.jpg | Dataset/Car Images/Train Images/Ford GT Coupe ... | Ford GT Coupe 2006 | 1067 | 1600 | 78 | 526 | 1489 | 908 | 112 |
| 8143 | 08144.jpg | Dataset/Car Images/Train Images/Audi 100 Sedan... | Audi 100 Sedan 1994 | 683 | 883 | 20 | 240 | 862 | 677 | 17 |
8144 rows × 10 columns
We can see that train images are mapped to its classes and annotations.
We will rename Unnamed columns to X1,Y1, X2, Y2 accordingly.
car_train_image_details.rename(columns = {'Bounding Box coordinates': 'X1','Unnamed: 2':'Y1','Unnamed: 3':'X2','Unnamed: 4':'Y2'},inplace = True)
car_train_image_details
| Image Name | imagePath | class | height | width | X1 | Y1 | X2 | Y2 | Image class | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 00001.jpg | Dataset/Car Images/Train Images/Audi TTS Coupe... | Audi TTS Coupe 2012 | 400 | 600 | 39 | 116 | 569 | 375 | 14 |
| 1 | 00002.jpg | Dataset/Car Images/Train Images/Acura TL Sedan... | Acura TL Sedan 2012 | 675 | 900 | 36 | 116 | 868 | 587 | 3 |
| 2 | 00003.jpg | Dataset/Car Images/Train Images/Dodge Dakota C... | Dodge Dakota Club Cab 2007 | 480 | 640 | 85 | 109 | 601 | 381 | 91 |
| 3 | 00004.jpg | Dataset/Car Images/Train Images/Hyundai Sonata... | Hyundai Sonata Hybrid Sedan 2012 | 1386 | 2100 | 621 | 393 | 1484 | 1096 | 134 |
| 4 | 00005.jpg | Dataset/Car Images/Train Images/Ford F-450 Sup... | Ford F-450 Super Duty Crew Cab 2012 | 108 | 144 | 14 | 36 | 133 | 99 | 106 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 8139 | 08140.jpg | Dataset/Car Images/Train Images/Chrysler Town ... | Chrysler Town and Country Minivan 2012 | 360 | 424 | 3 | 44 | 423 | 336 | 78 |
| 8140 | 08141.jpg | Dataset/Car Images/Train Images/smart fortwo C... | smart fortwo Convertible 2012 | 600 | 800 | 138 | 150 | 706 | 523 | 196 |
| 8141 | 08142.jpg | Dataset/Car Images/Train Images/Mercedes-Benz ... | Mercedes-Benz SL-Class Coupe 2009 | 469 | 750 | 26 | 246 | 660 | 449 | 163 |
| 8142 | 08143.jpg | Dataset/Car Images/Train Images/Ford GT Coupe ... | Ford GT Coupe 2006 | 1067 | 1600 | 78 | 526 | 1489 | 908 | 112 |
| 8143 | 08144.jpg | Dataset/Car Images/Train Images/Audi 100 Sedan... | Audi 100 Sedan 1994 | 683 | 883 | 20 | 240 | 862 | 677 | 17 |
8144 rows × 10 columns
car_train_image_details['Image class'].value_counts()
119 68
79 49
161 48
167 48
144 47
..
175 31
64 30
158 29
99 28
136 24
Name: Image class, Length: 196, dtype: int64
car_train_image_details['class'].value_counts()
GMC Savana Van 2012 68
Chrysler 300 SRT-8 2010 49
Mercedes-Benz 300-Class Convertible 1993 48
Mitsubishi Lancer Sedan 2012 48
Chevrolet Corvette ZR1 2012 47
..
Rolls-Royce Phantom Drophead Coupe Convertible 2012 31
Chevrolet Express Cargo Van 2007 30
Maybach Landaulet Convertible 2012 29
FIAT 500 Abarth 2012 28
Hyundai Accent Sedan 2012 24
Name: class, Length: 196, dtype: int64
# Visualizing train images
plt.figure(figsize=(20,10))
for i in range(20):
plt.subplot(4, 5, i + 1)
plt.imshow(plt.imread(car_train_image_details['imagePath'][i]))
Now Let us visualize train images with its bounding box.
def display_image_with_bounding_box(imageDetails):
imagePath=imageDetails.imagePath
img_arr = cv2.imread(imagePath)
cv2.rectangle(img_arr, (imageDetails.X1, imageDetails.Y1), (imageDetails.X2, imageDetails.Y2), (255, 0, 0), 3)
plt.imshow(img_arr)
print(imageDetails['class'])
display_image_with_bounding_box(car_train_image_details.iloc[10,:])
Buick Verano Sedan 2012
display_image_with_bounding_box(car_train_image_details.iloc[3333,:])
Plymouth Neon Coupe 1999
display_image_with_bounding_box(car_train_image_details.iloc[8143,:])
Audi 100 Sedan 1994
# Visualizing First 20 train images with bounding boxes
plt.figure(figsize=(20,10))
for i in range(20):
plt.subplot(4, 5, i + 1)
display_image_with_bounding_box(car_train_image_details.iloc[i,:])
Audi TTS Coupe 2012 Acura TL Sedan 2012 Dodge Dakota Club Cab 2007 Hyundai Sonata Hybrid Sedan 2012 Ford F-450 Super Duty Crew Cab 2012 Geo Metro Convertible 1993 Dodge Journey SUV 2012 Dodge Charger Sedan 2012 Mitsubishi Lancer Sedan 2012 Chevrolet Traverse SUV 2012 Buick Verano Sedan 2012 Toyota Sequoia SUV 2012 Hyundai Elantra Sedan 2007 Dodge Caravan Minivan 1997 Volvo C30 Hatchback 2012 Plymouth Neon Coupe 1999 Audi TTS Coupe 2012 Chevrolet Malibu Sedan 2007 Volkswagen Beetle Hatchback 2012 Chevrolet Corvette Ron Fellows Edition Z06 2007
car_test_image_details = pd.merge(cars_test_data, cars_test_annotations,
on='Image Name',
how='outer')
car_test_image_details
| Image Name | imagePath | class | height | width | Bounding Box coordinates | Unnamed: 2 | Unnamed: 3 | Unnamed: 4 | Image class | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 00001.jpg | Dataset/Car Images/Test Images/Suzuki Aerio Se... | Suzuki Aerio Sedan 2007 | 182 | 276 | 30 | 52 | 246 | 147 | 181 |
| 1 | 00002.jpg | Dataset/Car Images/Test Images/Ferrari 458 Ita... | Ferrari 458 Italia Convertible 2012 | 360 | 640 | 100 | 19 | 576 | 203 | 103 |
| 2 | 00003.jpg | Dataset/Car Images/Test Images/Jeep Patriot SU... | Jeep Patriot SUV 2012 | 741 | 1024 | 51 | 105 | 968 | 659 | 145 |
| 3 | 00004.jpg | Dataset/Car Images/Test Images/Toyota Camry Se... | Toyota Camry Sedan 2012 | 480 | 640 | 67 | 84 | 581 | 407 | 187 |
| 4 | 00005.jpg | Dataset/Car Images/Test Images/Tesla Model S S... | Tesla Model S Sedan 2012 | 373 | 600 | 140 | 151 | 593 | 339 | 185 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 8036 | 08037.jpg | Dataset/Car Images/Test Images/Chevrolet Sonic... | Chevrolet Sonic Sedan 2012 | 800 | 1200 | 49 | 57 | 1169 | 669 | 63 |
| 8037 | 08038.jpg | Dataset/Car Images/Test Images/Audi V8 Sedan 1... | Audi V8 Sedan 1994 | 480 | 640 | 23 | 18 | 640 | 459 | 16 |
| 8038 | 08039.jpg | Dataset/Car Images/Test Images/Audi 100 Sedan ... | Audi 100 Sedan 1994 | 303 | 635 | 33 | 27 | 602 | 252 | 17 |
| 8039 | 08040.jpg | Dataset/Car Images/Test Images/BMW Z4 Converti... | BMW Z4 Convertible 2012 | 427 | 640 | 33 | 142 | 521 | 376 | 38 |
| 8040 | 08041.jpg | Dataset/Car Images/Test Images/BMW X5 SUV 2007... | BMW X5 SUV 2007 | 426 | 640 | 77 | 73 | 506 | 380 | 32 |
8041 rows × 10 columns
#Renaming unnamed columns
car_test_image_details.rename(columns = {'Bounding Box coordinates': 'X1','Unnamed: 2':'Y1','Unnamed: 3':'X2','Unnamed: 4':'Y2'},inplace = True)
car_test_image_details['Image class'].value_counts()
119 68
161 48
79 48
167 47
20 46
..
175 30
64 29
158 29
99 27
136 24
Name: Image class, Length: 196, dtype: int64
car_test_image_details['class'].value_counts()
GMC Savana Van 2012 68
Mercedes-Benz 300-Class Convertible 1993 48
Chrysler 300 SRT-8 2010 48
Mitsubishi Lancer Sedan 2012 47
Audi S6 Sedan 2011 46
..
Rolls-Royce Phantom Drophead Coupe Convertible 2012 30
Maybach Landaulet Convertible 2012 29
Chevrolet Express Cargo Van 2007 29
FIAT 500 Abarth 2012 27
Hyundai Accent Sedan 2012 24
Name: class, Length: 196, dtype: int64
# Visualizing test images
plt.figure(figsize=(20,10))
for i in range(20):
plt.subplot(4, 5, i + 1)
plt.imshow(plt.imread(car_test_image_details['imagePath'][i]))
We can see that train images are mapped to its classes and annotations. Let us visualize 5 test images with its bounding box.
display_image_with_bounding_box(car_test_image_details.iloc[0,:])
Suzuki Aerio Sedan 2007
display_image_with_bounding_box(car_test_image_details.iloc[10,:]),
Buick Verano Sedan 2012
(None,)
display_image_with_bounding_box(car_test_image_details.iloc[3000,:])
Mercedes-Benz S-Class Sedan 2012
display_image_with_bounding_box(car_test_image_details.iloc[8000,:])
Hyundai Veloster Hatchback 2012
display_image_with_bounding_box(car_test_image_details.iloc[8040,:])
BMW X5 SUV 2007
# Visualizing First 20 test images with bounding boxes
plt.figure(figsize=(20,10))
for i in range(20):
plt.subplot(4, 5, i + 1)
display_image_with_bounding_box(car_test_image_details.iloc[i,:])
Suzuki Aerio Sedan 2007 Ferrari 458 Italia Convertible 2012 Jeep Patriot SUV 2012 Toyota Camry Sedan 2012 Tesla Model S Sedan 2012 Chrysler Town and Country Minivan 2012 GMC Terrain SUV 2012 Mercedes-Benz S-Class Sedan 2012 BMW X5 SUV 2007 Chevrolet HHR SS 2010 Buick Verano Sedan 2012 Ford Freestar Minivan 2007 Ford E-Series Wagon Van 2012 Hyundai Elantra Sedan 2007 Dodge Caliber Wagon 2012 Cadillac CTS-V Sedan 2012 Land Rover Range Rover SUV 2012 BMW X6 SUV 2012 Audi S5 Coupe 2012 BMW X5 SUV 2007
Importing Car names.
car_labels_data = pd.read_csv('Dataset/Car names and make.csv',header=None,names =['labels'])
car_labels_data
| labels | |
|---|---|
| 0 | AM General Hummer SUV 2000 |
| 1 | Acura RL Sedan 2012 |
| 2 | Acura TL Sedan 2012 |
| 3 | Acura TL Type-S 2008 |
| 4 | Acura TSX Sedan 2012 |
| ... | ... |
| 191 | Volkswagen Beetle Hatchback 2012 |
| 192 | Volvo C30 Hatchback 2012 |
| 193 | Volvo 240 Sedan 1993 |
| 194 | Volvo XC90 SUV 2007 |
| 195 | smart fortwo Convertible 2012 |
196 rows × 1 columns
print('Found one Class name: Ram C/V Cargo Van Minivan 2012, not in sync with directory path, renaming it')
car_labels_data['labels'].replace({"Ram C/V Cargo Van Minivan 2012": "Ram C-V Cargo Van Minivan 2012"}, inplace=True)
Found one Class name: Ram C/V Cargo Van Minivan 2012, not in sync with directory path, renaming it
car_labels_data.sort_values(['labels'],
axis=0,
ascending=[True],
inplace=True)
car_labels_data = car_labels_data.reset_index()
car_labels_data['year'] = car_labels_data['labels'].str[-4:]
car_labels_data['labels'] = car_labels_data['labels'].apply(lambda x:x[:-4])
car_labels_data
| index | labels | year | |
|---|---|---|---|
| 0 | 0 | AM General Hummer SUV | 2000 |
| 1 | 5 | Acura Integra Type R | 2001 |
| 2 | 1 | Acura RL Sedan | 2012 |
| 3 | 2 | Acura TL Sedan | 2012 |
| 4 | 3 | Acura TL Type-S | 2008 |
| ... | ... | ... | ... |
| 191 | 189 | Volkswagen Golf Hatchback | 2012 |
| 192 | 193 | Volvo 240 Sedan | 1993 |
| 193 | 192 | Volvo C30 Hatchback | 2012 |
| 194 | 194 | Volvo XC90 SUV | 2007 |
| 195 | 195 | smart fortwo Convertible | 2012 |
196 rows × 3 columns
# Function which returns last word
def lastWord(string):
# split by space and converting
# string to list and
lis = list(string.split(" "))
# length of list
length = len(lis)
# returning last element in list
last_word= lis[length-2]
if(last_word == 'R'):
last_word='Type R'
return last_word
lastWord(car_labels_data.iloc[0,:].labels)
'SUV'
lastWord(car_labels_data.iloc[1,:].labels)
'Type R'
car_labels_data['type'] = car_labels_data['labels'].apply(lambda x:lastWord(x))
car_labels_data
| index | labels | year | type | |
|---|---|---|---|---|
| 0 | 0 | AM General Hummer SUV | 2000 | SUV |
| 1 | 5 | Acura Integra Type R | 2001 | Type R |
| 2 | 1 | Acura RL Sedan | 2012 | Sedan |
| 3 | 2 | Acura TL Sedan | 2012 | Sedan |
| 4 | 3 | Acura TL Type-S | 2008 | Type-S |
| ... | ... | ... | ... | ... |
| 191 | 189 | Volkswagen Golf Hatchback | 2012 | Hatchback |
| 192 | 193 | Volvo 240 Sedan | 1993 | Sedan |
| 193 | 192 | Volvo C30 Hatchback | 2012 | Hatchback |
| 194 | 194 | Volvo XC90 SUV | 2007 | SUV |
| 195 | 195 | smart fortwo Convertible | 2012 | Convertible |
196 rows × 4 columns
car_labels_data.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 196 entries, 0 to 195 Data columns (total 4 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 index 196 non-null int64 1 labels 196 non-null object 2 year 196 non-null object 3 type 196 non-null object dtypes: int64(1), object(3) memory usage: 6.2+ KB
car_labels_data.type.value_counts()
Sedan 46 SUV 34 Convertible 26 Coupe 25 Cab 17 Hatchback 13 Van 7 Minivan 6 Wagon 6 SS 3 SRT-8 2 Z06 1 SuperCab 1 GS 1 Type-S 1 Superleggera 1 SRT8 1 Abarth 1 Type R 1 ZR1 1 IPL 1 XKR 1 Name: type, dtype: int64
car_labels_data.labels.value_counts()
Bentley Continental GT Coupe 2
Volkswagen Golf Hatchback 2
Ford F-150 Regular Cab 2
Dodge Durango SUV 2
Honda Odyssey Minivan 2
..
BMW 1 Series Convertible 1
Dodge Challenger SRT8 1
GMC Acadia SUV 1
Lamborghini Gallardo LP 570-4 Superleggera 1
Infiniti G Coupe IPL 1
Name: labels, Length: 189, dtype: int64
plt.figure(figsize=(10,10))
sns.countplot(x='year',data=car_labels_data)
plt.yticks(rotation = 0)
plt.xticks(rotation = 90)
plt.show()
plt.figure(figsize=(10,10))
plt.xticks(rotation='vertical')
sns.countplot(data=car_labels_data, x='type', palette='plasma')
<AxesSubplot:xlabel='type', ylabel='count'>
fig, (ax1) = plt.subplots(ncols=1, figsize=(20, 20))
df_car_model_type = pd.DataFrame(car_labels_data['type'].value_counts()).reset_index()
df_car_model_type.columns = ['Car Model Type', 'count']
colors = ['purple', 'red', 'blue', 'yellow', 'green']
labels = car_labels_data['type'].unique()
type_count = car_labels_data['type'].nunique()
ax1.pie(df_car_model_type['count'], labels = labels, colors=colors, explode=[0.05]*type_count, autopct='%.0f%%')
ax1.set_title('Cars Model Type')
ax1.legend(labels, loc = 'upper right')
<matplotlib.legend.Legend at 0x7fa659938b20>
fig, (ax1) = plt.subplots(ncols=1, figsize=(20, 20))
df_car_model_year = pd.DataFrame(car_labels_data['year'].value_counts()).reset_index()
df_car_model_year.columns = ['Car Model Year', 'count']
colors = ['gold', 'red', '#FBCFCD', '#F5F5DC', 'green']
labels = car_labels_data['year'].unique()
year_count = car_labels_data['year'].nunique()
ax1.pie(df_car_model_year['count'], labels = labels, colors=colors, explode=[0.05]*year_count, autopct='%.0f%%')
ax1.set_title('Cars Model Year')
ax1.legend(labels, loc = 'upper right')
<matplotlib.legend.Legend at 0x7fa67a17ecd0>
figure = plt.figure(figsize=(15,7))
sns.scatterplot(x='year', y='type', data=car_labels_data)
<AxesSubplot:xlabel='year', ylabel='type'>
figure = plt.figure(figsize=(15,7))
sns.scatterplot(car_labels_data['year'], car_labels_data['type'], hue=car_labels_data['year'], palette='Set2')
<AxesSubplot:xlabel='year', ylabel='type'>
# filtering the rows for Sedan
df=car_labels_data[car_labels_data['labels'].str.contains('Sedan')]
sns.catplot(y="labels", x="year", data=df,kind="swarm",height=8, aspect=1)
<seaborn.axisgrid.FacetGrid at 0x7fa65b1a1b20>
figure = plt.figure(figsize=(15,15))
plt.xticks(rotation='vertical')
sns.countplot(data=df, x='labels',palette='plasma')
<AxesSubplot:xlabel='labels', ylabel='count'>
# filtering the rows for SUV
df2=car_labels_data[car_labels_data['labels'].str.contains('SUV')]
sns.catplot(y="labels", x="year", data=df2,kind="swarm",height=8, aspect=1)
<seaborn.axisgrid.FacetGrid at 0x7fa6760a6b20>
figure = plt.figure(figsize=(15,15))
plt.xticks(rotation='vertical')
sns.countplot(data=df2, x='labels')
<AxesSubplot:xlabel='labels', ylabel='count'>
# filtering the rows for Convertible
df3=car_labels_data[car_labels_data['labels'].str.contains('Convertible')]
sns.catplot(y="labels", x="year", data=df3,kind="swarm",height=8, aspect=1)
<seaborn.axisgrid.FacetGrid at 0x7fa67aa54820>
figure = plt.figure(figsize=(15,15))
plt.xticks(rotation='vertical')
sns.countplot(data=df3, x='labels')
<AxesSubplot:xlabel='labels', ylabel='count'>
# filtering the rows for Hatchback
df4=car_labels_data[car_labels_data['labels'].str.contains('Hatchback')]
sns.catplot(y="labels", x="year", data=df4,kind="swarm",height=8, aspect=1)
<seaborn.axisgrid.FacetGrid at 0x7fa67aa4ffa0>
figure = plt.figure(figsize=(15,15))
plt.xticks(rotation='vertical')
sns.countplot(data=df4, x='labels')
<AxesSubplot:xlabel='labels', ylabel='count'>
# filtering the rows for Coupe
df5=car_labels_data[car_labels_data['labels'].str.contains('Coupe')]
sns.catplot(y="labels", x="year", data=df5,kind="swarm",height=8, aspect=1)
<seaborn.axisgrid.FacetGrid at 0x7fa69b3df550>
figure = plt.figure(figsize=(15,15))
plt.xticks(rotation='vertical')
sns.countplot(data=df5, x='labels')
<AxesSubplot:xlabel='labels', ylabel='count'>
text = " ".join(name for name in car_labels_data.labels)
print ("There are {} words in the combination of all records.".format(len(text)))
There are 4669 words in the combination of all records.
from wordcloud import WordCloud
# Generate a word cloud image
wordcloud = WordCloud(background_color="black").generate(text)
figure = plt.figure(figsize=(15,15))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
car_labels = car_labels_data['labels'].to_list()
car_labels
['AM General Hummer SUV ', 'Acura Integra Type R ', 'Acura RL Sedan ', 'Acura TL Sedan ', 'Acura TL Type-S ', 'Acura TSX Sedan ', 'Acura ZDX Hatchback ', 'Aston Martin V8 Vantage Convertible ', 'Aston Martin V8 Vantage Coupe ', 'Aston Martin Virage Convertible ', 'Aston Martin Virage Coupe ', 'Audi 100 Sedan ', 'Audi 100 Wagon ', 'Audi A5 Coupe ', 'Audi R8 Coupe ', 'Audi RS 4 Convertible ', 'Audi S4 Sedan ', 'Audi S4 Sedan ', 'Audi S5 Convertible ', 'Audi S5 Coupe ', 'Audi S6 Sedan ', 'Audi TT Hatchback ', 'Audi TT RS Coupe ', 'Audi TTS Coupe ', 'Audi V8 Sedan ', 'BMW 1 Series Convertible ', 'BMW 1 Series Coupe ', 'BMW 3 Series Sedan ', 'BMW 3 Series Wagon ', 'BMW 6 Series Convertible ', 'BMW ActiveHybrid 5 Sedan ', 'BMW M3 Coupe ', 'BMW M5 Sedan ', 'BMW M6 Convertible ', 'BMW X3 SUV ', 'BMW X5 SUV ', 'BMW X6 SUV ', 'BMW Z4 Convertible ', 'Bentley Arnage Sedan ', 'Bentley Continental Flying Spur Sedan ', 'Bentley Continental GT Coupe ', 'Bentley Continental GT Coupe ', 'Bentley Continental Supersports Conv. Convertible ', 'Bentley Mulsanne Sedan ', 'Bugatti Veyron 16.4 Convertible ', 'Bugatti Veyron 16.4 Coupe ', 'Buick Enclave SUV ', 'Buick Rainier SUV ', 'Buick Regal GS ', 'Buick Verano Sedan ', 'Cadillac CTS-V Sedan ', 'Cadillac Escalade EXT Crew Cab ', 'Cadillac SRX SUV ', 'Chevrolet Avalanche Crew Cab ', 'Chevrolet Camaro Convertible ', 'Chevrolet Cobalt SS ', 'Chevrolet Corvette Convertible ', 'Chevrolet Corvette Ron Fellows Edition Z06 ', 'Chevrolet Corvette ZR1 ', 'Chevrolet Express Cargo Van ', 'Chevrolet Express Van ', 'Chevrolet HHR SS ', 'Chevrolet Impala Sedan ', 'Chevrolet Malibu Hybrid Sedan ', 'Chevrolet Malibu Sedan ', 'Chevrolet Monte Carlo Coupe ', 'Chevrolet Silverado 1500 Classic Extended Cab ', 'Chevrolet Silverado 1500 Extended Cab ', 'Chevrolet Silverado 1500 Hybrid Crew Cab ', 'Chevrolet Silverado 1500 Regular Cab ', 'Chevrolet Silverado 2500HD Regular Cab ', 'Chevrolet Sonic Sedan ', 'Chevrolet Tahoe Hybrid SUV ', 'Chevrolet TrailBlazer SS ', 'Chevrolet Traverse SUV ', 'Chrysler 300 SRT-8 ', 'Chrysler Aspen SUV ', 'Chrysler Crossfire Convertible ', 'Chrysler PT Cruiser Convertible ', 'Chrysler Sebring Convertible ', 'Chrysler Town and Country Minivan ', 'Daewoo Nubira Wagon ', 'Dodge Caliber Wagon ', 'Dodge Caliber Wagon ', 'Dodge Caravan Minivan ', 'Dodge Challenger SRT8 ', 'Dodge Charger SRT-8 ', 'Dodge Charger Sedan ', 'Dodge Dakota Club Cab ', 'Dodge Dakota Crew Cab ', 'Dodge Durango SUV ', 'Dodge Durango SUV ', 'Dodge Journey SUV ', 'Dodge Magnum Wagon ', 'Dodge Ram Pickup 3500 Crew Cab ', 'Dodge Ram Pickup 3500 Quad Cab ', 'Dodge Sprinter Cargo Van ', 'Eagle Talon Hatchback ', 'FIAT 500 Abarth ', 'FIAT 500 Convertible ', 'Ferrari 458 Italia Convertible ', 'Ferrari 458 Italia Coupe ', 'Ferrari California Convertible ', 'Ferrari FF Coupe ', 'Fisker Karma Sedan ', 'Ford E-Series Wagon Van ', 'Ford Edge SUV ', 'Ford Expedition EL SUV ', 'Ford F-150 Regular Cab ', 'Ford F-150 Regular Cab ', 'Ford F-450 Super Duty Crew Cab ', 'Ford Fiesta Sedan ', 'Ford Focus Sedan ', 'Ford Freestar Minivan ', 'Ford GT Coupe ', 'Ford Mustang Convertible ', 'Ford Ranger SuperCab ', 'GMC Acadia SUV ', 'GMC Canyon Extended Cab ', 'GMC Savana Van ', 'GMC Terrain SUV ', 'GMC Yukon Hybrid SUV ', 'Geo Metro Convertible ', 'HUMMER H2 SUT Crew Cab ', 'HUMMER H3T Crew Cab ', 'Honda Accord Coupe ', 'Honda Accord Sedan ', 'Honda Odyssey Minivan ', 'Honda Odyssey Minivan ', 'Hyundai Accent Sedan ', 'Hyundai Azera Sedan ', 'Hyundai Elantra Sedan ', 'Hyundai Elantra Touring Hatchback ', 'Hyundai Genesis Sedan ', 'Hyundai Santa Fe SUV ', 'Hyundai Sonata Hybrid Sedan ', 'Hyundai Sonata Sedan ', 'Hyundai Tucson SUV ', 'Hyundai Veloster Hatchback ', 'Hyundai Veracruz SUV ', 'Infiniti G Coupe IPL ', 'Infiniti QX56 SUV ', 'Isuzu Ascender SUV ', 'Jaguar XK XKR ', 'Jeep Compass SUV ', 'Jeep Grand Cherokee SUV ', 'Jeep Liberty SUV ', 'Jeep Patriot SUV ', 'Jeep Wrangler SUV ', 'Lamborghini Aventador Coupe ', 'Lamborghini Diablo Coupe ', 'Lamborghini Gallardo LP 570-4 Superleggera ', 'Lamborghini Reventon Coupe ', 'Land Rover LR2 SUV ', 'Land Rover Range Rover SUV ', 'Lincoln Town Car Sedan ', 'MINI Cooper Roadster Convertible ', 'Maybach Landaulet Convertible ', 'Mazda Tribute SUV ', 'McLaren MP4-12C Coupe ', 'Mercedes-Benz 300-Class Convertible ', 'Mercedes-Benz C-Class Sedan ', 'Mercedes-Benz E-Class Sedan ', 'Mercedes-Benz S-Class Sedan ', 'Mercedes-Benz SL-Class Coupe ', 'Mercedes-Benz Sprinter Van ', 'Mitsubishi Lancer Sedan ', 'Nissan 240SX Coupe ', 'Nissan Juke Hatchback ', 'Nissan Leaf Hatchback ', 'Nissan NV Passenger Van ', 'Plymouth Neon Coupe ', 'Porsche Panamera Sedan ', 'Ram C-V Cargo Van Minivan ', 'Rolls-Royce Ghost Sedan ', 'Rolls-Royce Phantom Drophead Coupe Convertible ', 'Rolls-Royce Phantom Sedan ', 'Scion xD Hatchback ', 'Spyker C8 Convertible ', 'Spyker C8 Coupe ', 'Suzuki Aerio Sedan ', 'Suzuki Kizashi Sedan ', 'Suzuki SX4 Hatchback ', 'Suzuki SX4 Sedan ', 'Tesla Model S Sedan ', 'Toyota 4Runner SUV ', 'Toyota Camry Sedan ', 'Toyota Corolla Sedan ', 'Toyota Sequoia SUV ', 'Volkswagen Beetle Hatchback ', 'Volkswagen Golf Hatchback ', 'Volkswagen Golf Hatchback ', 'Volvo 240 Sedan ', 'Volvo C30 Hatchback ', 'Volvo XC90 SUV ', 'smart fortwo Convertible ']
#Creating a Dictionary of training image classes.
num_classes = car_train_image_details['Image class'].unique()
label_class_dict = dict(zip(car_train_image_details['class'], car_train_image_details['Image class']))
len(num_classes)
196
label_class_dict
{'Audi TTS Coupe 2012': 14,
'Acura TL Sedan 2012': 3,
'Dodge Dakota Club Cab 2007': 91,
'Hyundai Sonata Hybrid Sedan 2012': 134,
'Ford F-450 Super Duty Crew Cab 2012': 106,
'Geo Metro Convertible 1993': 123,
'Dodge Journey SUV 2012': 89,
'Dodge Charger Sedan 2012': 96,
'Mitsubishi Lancer Sedan 2012': 167,
'Chevrolet Traverse SUV 2012': 58,
'Buick Verano Sedan 2012': 49,
'Toyota Sequoia SUV 2012': 186,
'Hyundai Elantra Sedan 2007': 135,
'Dodge Caravan Minivan 1997': 85,
'Volvo C30 Hatchback 2012': 193,
'Plymouth Neon Coupe 1999': 172,
'Chevrolet Malibu Sedan 2007': 73,
'Volkswagen Beetle Hatchback 2012': 192,
'Chevrolet Corvette Ron Fellows Edition Z06 2007': 57,
'Chrysler 300 SRT-8 2010': 79,
'BMW M6 Convertible 2010': 36,
'GMC Yukon Hybrid SUV 2012': 120,
'Nissan Juke Hatchback 2012': 170,
'Volvo 240 Sedan 1993': 194,
'Suzuki SX4 Sedan 2012': 184,
'Dodge Ram Pickup 3500 Crew Cab 2010': 86,
'Spyker C8 Coupe 2009': 180,
'Land Rover Range Rover SUV 2012': 154,
'Hyundai Elantra Touring Hatchback 2012': 139,
'Chevrolet Cobalt SS 2010': 66,
'Hyundai Veracruz SUV 2012': 133,
'Ferrari 458 Italia Coupe 2012': 104,
'BMW Z4 Convertible 2012': 38,
'Dodge Charger SRT-8 2009': 97,
'Fisker Karma Sedan 2012': 105,
'Infiniti QX56 SUV 2011': 142,
'Audi A5 Coupe 2012': 13,
'Volkswagen Golf Hatchback 1991': 191,
'GMC Savana Van 2012': 119,
'Audi TT RS Coupe 2012': 25,
'Rolls-Royce Phantom Sedan 2012': 177,
'Porsche Panamera Sedan 2012': 173,
'Bentley Continental GT Coupe 2012': 42,
'Jeep Grand Cherokee SUV 2012': 148,
'Audi R8 Coupe 2012': 15,
'Cadillac Escalade EXT Crew Cab 2007': 53,
'Bentley Continental Flying Spur Sedan 2007': 44,
'Chevrolet Avalanche Crew Cab 2012': 65,
'Dodge Dakota Crew Cab 2010': 90,
'HUMMER H3T Crew Cab 2010': 124,
'Ford F-150 Regular Cab 2007': 114,
'Volkswagen Golf Hatchback 2012': 190,
'Ferrari FF Coupe 2012': 101,
'Toyota Camry Sedan 2012': 187,
'Aston Martin V8 Vantage Convertible 2012': 8,
'Audi 100 Sedan 1994': 17,
'Ford Ranger SuperCab 2011': 111,
'GMC Canyon Extended Cab 2012': 122,
'Acura TSX Sedan 2012': 5,
'BMW 3 Series Sedan 2012': 29,
'Honda Odyssey Minivan 2012': 126,
'Dodge Durango SUV 2012': 94,
'Toyota Corolla Sedan 2012': 188,
'Chevrolet Camaro Convertible 2012': 59,
'Ford Edge SUV 2012': 110,
'Bentley Continental GT Coupe 2007': 43,
'Audi 100 Wagon 1994': 18,
'Ford E-Series Wagon Van 2012': 116,
'Jeep Patriot SUV 2012': 145,
'Audi S6 Sedan 2011': 20,
'Mercedes-Benz S-Class Sedan 2012': 165,
'Hyundai Sonata Sedan 2012': 138,
'Rolls-Royce Phantom Drophead Coupe Convertible 2012': 175,
'Ford GT Coupe 2006': 112,
'Cadillac CTS-V Sedan 2012': 51,
'BMW X3 SUV 2012': 37,
'Chevrolet Express Van 2007': 71,
'Chevrolet Impala Sedan 2007': 61,
'Chevrolet Silverado 1500 Extended Cab 2012': 74,
'Mercedes-Benz C-Class Sedan 2012': 162,
'Hyundai Santa Fe SUV 2012': 131,
'Dodge Sprinter Cargo Van 2009': 88,
'GMC Acadia SUV 2012': 121,
'Hyundai Genesis Sedan 2012': 137,
'Dodge Caliber Wagon 2012': 83,
'Jeep Liberty SUV 2012': 147,
'Mercedes-Benz 300-Class Convertible 1993': 161,
'Ford Expedition EL SUV 2009': 109,
'BMW 1 Series Coupe 2012': 28,
'Jaguar XK XKR 2012': 144,
'Hyundai Accent Sedan 2012': 136,
'Isuzu Ascender SUV 2008': 143,
'Nissan 240SX Coupe 1998': 171,
'Scion xD Hatchback 2012': 178,
'Chevrolet Corvette ZR1 2012': 56,
'Bentley Arnage Sedan 2009': 40,
'Chevrolet HHR SS 2010': 60,
'Land Rover LR2 SUV 2012': 155,
'Hyundai Azera Sedan 2012': 140,
'Chrysler Aspen SUV 2009': 76,
'Buick Regal GS 2012': 47,
'BMW 3 Series Wagon 2012': 30,
'Jeep Compass SUV 2012': 149,
'Ram C-V Cargo Van Minivan 2012': 174,
'Spyker C8 Convertible 2009': 179,
'Audi S4 Sedan 2007': 24,
'Rolls-Royce Ghost Sedan 2012': 176,
'AM General Hummer SUV 2000': 1,
'Ford Freestar Minivan 2007': 108,
'Bentley Mulsanne Sedan 2011': 41,
'Audi TT Hatchback 2011': 19,
'Mercedes-Benz SL-Class Coupe 2009': 163,
'Chevrolet Silverado 1500 Hybrid Crew Cab 2012': 54,
'Buick Enclave SUV 2012': 50,
'Chevrolet TrailBlazer SS 2009': 68,
'HUMMER H2 SUT Crew Cab 2009': 125,
'McLaren MP4-12C Coupe 2012': 160,
'Dodge Challenger SRT8 2011': 93,
'Suzuki SX4 Hatchback 2012': 183,
'Bugatti Veyron 16.4 Convertible 2009': 45,
'Toyota 4Runner SUV 2012': 189,
'Buick Rainier SUV 2007': 48,
'Chrysler Sebring Convertible 2010': 77,
'Acura Integra Type R 2001': 6,
'Audi V8 Sedan 1994': 16,
'Audi RS 4 Convertible 2008': 12,
'Honda Accord Coupe 2012': 128,
'Audi S4 Sedan 2012': 23,
'Aston Martin Virage Coupe 2012': 11,
'Chevrolet Sonic Sedan 2012': 63,
'Chevrolet Monte Carlo Coupe 2007': 72,
'Volvo XC90 SUV 2007': 195,
'Ford Mustang Convertible 2007': 107,
'Aston Martin Virage Convertible 2012': 10,
'smart fortwo Convertible 2012': 196,
'FIAT 500 Abarth 2012': 99,
'Infiniti G Coupe IPL 2012': 141,
'Dodge Caliber Wagon 2007': 84,
'Hyundai Tucson SUV 2012': 132,
'Acura ZDX Hatchback 2012': 7,
'BMW ActiveHybrid 5 Sedan 2012': 26,
'Ferrari California Convertible 2012': 102,
'Nissan Leaf Hatchback 2012': 168,
'Lamborghini Diablo Coupe 2001': 153,
'Audi S5 Convertible 2012': 21,
'BMW 6 Series Convertible 2007': 31,
'Ferrari 458 Italia Convertible 2012': 103,
'Chevrolet Silverado 2500HD Regular Cab 2012': 69,
'Chevrolet Corvette Convertible 2012': 55,
'Bugatti Veyron 16.4 Coupe 2009': 46,
'Tesla Model S Sedan 2012': 185,
'FIAT 500 Convertible 2012': 100,
'Hyundai Veloster Hatchback 2012': 130,
'Lincoln Town Car Sedan 2011': 156,
'Lamborghini Aventador Coupe 2012': 151,
'Dodge Ram Pickup 3500 Quad Cab 2009': 87,
'Nissan NV Passenger Van 2012': 169,
'Honda Odyssey Minivan 2007': 127,
'Maybach Landaulet Convertible 2012': 158,
'Chevrolet Silverado 1500 Regular Cab 2012': 75,
'Suzuki Kizashi Sedan 2012': 182,
'Chevrolet Tahoe Hybrid SUV 2012': 62,
'Mercedes-Benz Sprinter Van 2012': 166,
'Suzuki Aerio Sedan 2007': 181,
'Audi S5 Coupe 2012': 22,
'Aston Martin V8 Vantage Coupe 2012': 9,
'Chevrolet Malibu Hybrid Sedan 2010': 67,
'Ford F-150 Regular Cab 2012': 113,
'Ford Fiesta Sedan 2012': 117,
'Ford Focus Sedan 2007': 115,
'Bentley Continental Supersports Conv. Convertible 2012': 39,
'Chevrolet Silverado 1500 Classic Extended Cab 2007': 70,
'BMW X5 SUV 2007': 32,
'Jeep Wrangler SUV 2012': 146,
'Acura TL Type-S 2008': 4,
'Chrysler Crossfire Convertible 2008': 80,
'Lamborghini Gallardo LP 570-4 Superleggera 2012': 152,
'Mercedes-Benz E-Class Sedan 2012': 164,
'Chevrolet Express Cargo Van 2007': 64,
'GMC Terrain SUV 2012': 118,
'Dodge Magnum Wagon 2008': 92,
'Honda Accord Sedan 2012': 129,
'Chrysler PT Cruiser Convertible 2008': 81,
'Mazda Tribute SUV 2011': 159,
'BMW M3 Coupe 2012': 34,
'Eagle Talon Hatchback 1998': 98,
'Daewoo Nubira Wagon 2002': 82,
'BMW X6 SUV 2012': 33,
'Lamborghini Reventon Coupe 2008': 150,
'Cadillac SRX SUV 2012': 52,
'MINI Cooper Roadster Convertible 2012': 157,
'Acura RL Sedan 2012': 2,
'BMW 1 Series Convertible 2012': 27,
'Dodge Durango SUV 2007': 95,
'BMW M5 Sedan 2010': 35,
'Chrysler Town and Country Minivan 2012': 78}
car_train_image_details.sort_values(['Image class'],axis=0).reset_index()
| index | Image Name | imagePath | class | height | width | X1 | Y1 | X2 | Y2 | Image class | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 6173 | 06174.jpg | Dataset/Car Images/Train Images/AM General Hum... | AM General Hummer SUV 2000 | 179 | 300 | 1 | 1 | 300 | 179 | 1 |
| 1 | 5920 | 05921.jpg | Dataset/Car Images/Train Images/AM General Hum... | AM General Hummer SUV 2000 | 743 | 1024 | 111 | 213 | 907 | 683 | 1 |
| 2 | 3392 | 03393.jpg | Dataset/Car Images/Train Images/AM General Hum... | AM General Hummer SUV 2000 | 1600 | 2405 | 125 | 645 | 1845 | 1421 | 1 |
| 3 | 4543 | 04544.jpg | Dataset/Car Images/Train Images/AM General Hum... | AM General Hummer SUV 2000 | 200 | 339 | 18 | 18 | 328 | 190 | 1 |
| 4 | 945 | 00946.jpg | Dataset/Car Images/Train Images/AM General Hum... | AM General Hummer SUV 2000 | 219 | 460 | 48 | 24 | 441 | 202 | 1 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 8139 | 7894 | 07895.jpg | Dataset/Car Images/Train Images/smart fortwo C... | smart fortwo Convertible 2012 | 272 | 500 | 31 | 6 | 494 | 272 | 196 |
| 8140 | 6003 | 06004.jpg | Dataset/Car Images/Train Images/smart fortwo C... | smart fortwo Convertible 2012 | 194 | 259 | 8 | 7 | 256 | 190 | 196 |
| 8141 | 2102 | 02103.jpg | Dataset/Car Images/Train Images/smart fortwo C... | smart fortwo Convertible 2012 | 683 | 1024 | 34 | 262 | 766 | 650 | 196 |
| 8142 | 2391 | 02392.jpg | Dataset/Car Images/Train Images/smart fortwo C... | smart fortwo Convertible 2012 | 123 | 212 | 17 | 13 | 197 | 115 | 196 |
| 8143 | 4360 | 04361.jpg | Dataset/Car Images/Train Images/smart fortwo C... | smart fortwo Convertible 2012 | 168 | 300 | 19 | 40 | 210 | 150 | 196 |
8144 rows × 11 columns
car_test_image_details.sort_values(['Image class'],axis=0).reset_index()
| index | Image Name | imagePath | class | height | width | X1 | Y1 | X2 | Y2 | Image class | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 4116 | 04117.jpg | Dataset/Car Images/Test Images/AM General Humm... | AM General Hummer SUV 2000 | 743 | 1024 | 111 | 177 | 920 | 642 | 1 |
| 1 | 3875 | 03876.jpg | Dataset/Car Images/Test Images/AM General Humm... | AM General Hummer SUV 2000 | 69 | 93 | 8 | 5 | 85 | 69 | 1 |
| 2 | 5022 | 05023.jpg | Dataset/Car Images/Test Images/AM General Humm... | AM General Hummer SUV 2000 | 506 | 800 | 26 | 72 | 774 | 480 | 1 |
| 3 | 1517 | 01518.jpg | Dataset/Car Images/Test Images/AM General Humm... | AM General Hummer SUV 2000 | 520 | 800 | 26 | 62 | 763 | 504 | 1 |
| 4 | 1537 | 01538.jpg | Dataset/Car Images/Test Images/AM General Humm... | AM General Hummer SUV 2000 | 353 | 500 | 32 | 69 | 487 | 316 | 1 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 8036 | 7466 | 07467.jpg | Dataset/Car Images/Test Images/smart fortwo Co... | smart fortwo Convertible 2012 | 545 | 730 | 83 | 102 | 648 | 485 | 196 |
| 8037 | 4489 | 04490.jpg | Dataset/Car Images/Test Images/smart fortwo Co... | smart fortwo Convertible 2012 | 850 | 1280 | 63 | 121 | 1227 | 795 | 196 |
| 8038 | 3482 | 03483.jpg | Dataset/Car Images/Test Images/smart fortwo Co... | smart fortwo Convertible 2012 | 405 | 640 | 77 | 96 | 576 | 367 | 196 |
| 8039 | 5705 | 05706.jpg | Dataset/Car Images/Test Images/smart fortwo Co... | smart fortwo Convertible 2012 | 225 | 300 | 30 | 93 | 232 | 215 | 196 |
| 8040 | 1292 | 01293.jpg | Dataset/Car Images/Test Images/smart fortwo Co... | smart fortwo Convertible 2012 | 533 | 800 | 82 | 56 | 740 | 502 | 196 |
8041 rows × 11 columns
Let us check train and test csv data
car_train_image_details
| Image Name | imagePath | class | height | width | X1 | Y1 | X2 | Y2 | Image class | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 00001.jpg | Dataset/Car Images/Train Images/Audi TTS Coupe... | Audi TTS Coupe 2012 | 400 | 600 | 39 | 116 | 569 | 375 | 14 |
| 1 | 00002.jpg | Dataset/Car Images/Train Images/Acura TL Sedan... | Acura TL Sedan 2012 | 675 | 900 | 36 | 116 | 868 | 587 | 3 |
| 2 | 00003.jpg | Dataset/Car Images/Train Images/Dodge Dakota C... | Dodge Dakota Club Cab 2007 | 480 | 640 | 85 | 109 | 601 | 381 | 91 |
| 3 | 00004.jpg | Dataset/Car Images/Train Images/Hyundai Sonata... | Hyundai Sonata Hybrid Sedan 2012 | 1386 | 2100 | 621 | 393 | 1484 | 1096 | 134 |
| 4 | 00005.jpg | Dataset/Car Images/Train Images/Ford F-450 Sup... | Ford F-450 Super Duty Crew Cab 2012 | 108 | 144 | 14 | 36 | 133 | 99 | 106 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 8139 | 08140.jpg | Dataset/Car Images/Train Images/Chrysler Town ... | Chrysler Town and Country Minivan 2012 | 360 | 424 | 3 | 44 | 423 | 336 | 78 |
| 8140 | 08141.jpg | Dataset/Car Images/Train Images/smart fortwo C... | smart fortwo Convertible 2012 | 600 | 800 | 138 | 150 | 706 | 523 | 196 |
| 8141 | 08142.jpg | Dataset/Car Images/Train Images/Mercedes-Benz ... | Mercedes-Benz SL-Class Coupe 2009 | 469 | 750 | 26 | 246 | 660 | 449 | 163 |
| 8142 | 08143.jpg | Dataset/Car Images/Train Images/Ford GT Coupe ... | Ford GT Coupe 2006 | 1067 | 1600 | 78 | 526 | 1489 | 908 | 112 |
| 8143 | 08144.jpg | Dataset/Car Images/Train Images/Audi 100 Sedan... | Audi 100 Sedan 1994 | 683 | 883 | 20 | 240 | 862 | 677 | 17 |
8144 rows × 10 columns
car_test_image_details
| Image Name | imagePath | class | height | width | X1 | Y1 | X2 | Y2 | Image class | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 00001.jpg | Dataset/Car Images/Test Images/Suzuki Aerio Se... | Suzuki Aerio Sedan 2007 | 182 | 276 | 30 | 52 | 246 | 147 | 181 |
| 1 | 00002.jpg | Dataset/Car Images/Test Images/Ferrari 458 Ita... | Ferrari 458 Italia Convertible 2012 | 360 | 640 | 100 | 19 | 576 | 203 | 103 |
| 2 | 00003.jpg | Dataset/Car Images/Test Images/Jeep Patriot SU... | Jeep Patriot SUV 2012 | 741 | 1024 | 51 | 105 | 968 | 659 | 145 |
| 3 | 00004.jpg | Dataset/Car Images/Test Images/Toyota Camry Se... | Toyota Camry Sedan 2012 | 480 | 640 | 67 | 84 | 581 | 407 | 187 |
| 4 | 00005.jpg | Dataset/Car Images/Test Images/Tesla Model S S... | Tesla Model S Sedan 2012 | 373 | 600 | 140 | 151 | 593 | 339 | 185 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 8036 | 08037.jpg | Dataset/Car Images/Test Images/Chevrolet Sonic... | Chevrolet Sonic Sedan 2012 | 800 | 1200 | 49 | 57 | 1169 | 669 | 63 |
| 8037 | 08038.jpg | Dataset/Car Images/Test Images/Audi V8 Sedan 1... | Audi V8 Sedan 1994 | 480 | 640 | 23 | 18 | 640 | 459 | 16 |
| 8038 | 08039.jpg | Dataset/Car Images/Test Images/Audi 100 Sedan ... | Audi 100 Sedan 1994 | 303 | 635 | 33 | 27 | 602 | 252 | 17 |
| 8039 | 08040.jpg | Dataset/Car Images/Test Images/BMW Z4 Converti... | BMW Z4 Convertible 2012 | 427 | 640 | 33 | 142 | 521 | 376 | 38 |
| 8040 | 08041.jpg | Dataset/Car Images/Test Images/BMW X5 SUV 2007... | BMW X5 SUV 2007 | 426 | 640 | 77 | 73 | 506 | 380 | 32 |
8041 rows × 10 columns
CNN Model using Transfer Learning We are using the built-in module for Inception-ResNet V2 in tf.keras. We are not including the top and we won't import the output layer, as we don't have 1000 different categories. Instead we are adding a few layers for our 12 catagories.
nb_epoch = 20
batch_size = 300
width = 256
height = 256
label_class_dict
{'Audi TTS Coupe 2012': 14,
'Acura TL Sedan 2012': 3,
'Dodge Dakota Club Cab 2007': 91,
'Hyundai Sonata Hybrid Sedan 2012': 134,
'Ford F-450 Super Duty Crew Cab 2012': 106,
'Geo Metro Convertible 1993': 123,
'Dodge Journey SUV 2012': 89,
'Dodge Charger Sedan 2012': 96,
'Mitsubishi Lancer Sedan 2012': 167,
'Chevrolet Traverse SUV 2012': 58,
'Buick Verano Sedan 2012': 49,
'Toyota Sequoia SUV 2012': 186,
'Hyundai Elantra Sedan 2007': 135,
'Dodge Caravan Minivan 1997': 85,
'Volvo C30 Hatchback 2012': 193,
'Plymouth Neon Coupe 1999': 172,
'Chevrolet Malibu Sedan 2007': 73,
'Volkswagen Beetle Hatchback 2012': 192,
'Chevrolet Corvette Ron Fellows Edition Z06 2007': 57,
'Chrysler 300 SRT-8 2010': 79,
'BMW M6 Convertible 2010': 36,
'GMC Yukon Hybrid SUV 2012': 120,
'Nissan Juke Hatchback 2012': 170,
'Volvo 240 Sedan 1993': 194,
'Suzuki SX4 Sedan 2012': 184,
'Dodge Ram Pickup 3500 Crew Cab 2010': 86,
'Spyker C8 Coupe 2009': 180,
'Land Rover Range Rover SUV 2012': 154,
'Hyundai Elantra Touring Hatchback 2012': 139,
'Chevrolet Cobalt SS 2010': 66,
'Hyundai Veracruz SUV 2012': 133,
'Ferrari 458 Italia Coupe 2012': 104,
'BMW Z4 Convertible 2012': 38,
'Dodge Charger SRT-8 2009': 97,
'Fisker Karma Sedan 2012': 105,
'Infiniti QX56 SUV 2011': 142,
'Audi A5 Coupe 2012': 13,
'Volkswagen Golf Hatchback 1991': 191,
'GMC Savana Van 2012': 119,
'Audi TT RS Coupe 2012': 25,
'Rolls-Royce Phantom Sedan 2012': 177,
'Porsche Panamera Sedan 2012': 173,
'Bentley Continental GT Coupe 2012': 42,
'Jeep Grand Cherokee SUV 2012': 148,
'Audi R8 Coupe 2012': 15,
'Cadillac Escalade EXT Crew Cab 2007': 53,
'Bentley Continental Flying Spur Sedan 2007': 44,
'Chevrolet Avalanche Crew Cab 2012': 65,
'Dodge Dakota Crew Cab 2010': 90,
'HUMMER H3T Crew Cab 2010': 124,
'Ford F-150 Regular Cab 2007': 114,
'Volkswagen Golf Hatchback 2012': 190,
'Ferrari FF Coupe 2012': 101,
'Toyota Camry Sedan 2012': 187,
'Aston Martin V8 Vantage Convertible 2012': 8,
'Audi 100 Sedan 1994': 17,
'Ford Ranger SuperCab 2011': 111,
'GMC Canyon Extended Cab 2012': 122,
'Acura TSX Sedan 2012': 5,
'BMW 3 Series Sedan 2012': 29,
'Honda Odyssey Minivan 2012': 126,
'Dodge Durango SUV 2012': 94,
'Toyota Corolla Sedan 2012': 188,
'Chevrolet Camaro Convertible 2012': 59,
'Ford Edge SUV 2012': 110,
'Bentley Continental GT Coupe 2007': 43,
'Audi 100 Wagon 1994': 18,
'Ford E-Series Wagon Van 2012': 116,
'Jeep Patriot SUV 2012': 145,
'Audi S6 Sedan 2011': 20,
'Mercedes-Benz S-Class Sedan 2012': 165,
'Hyundai Sonata Sedan 2012': 138,
'Rolls-Royce Phantom Drophead Coupe Convertible 2012': 175,
'Ford GT Coupe 2006': 112,
'Cadillac CTS-V Sedan 2012': 51,
'BMW X3 SUV 2012': 37,
'Chevrolet Express Van 2007': 71,
'Chevrolet Impala Sedan 2007': 61,
'Chevrolet Silverado 1500 Extended Cab 2012': 74,
'Mercedes-Benz C-Class Sedan 2012': 162,
'Hyundai Santa Fe SUV 2012': 131,
'Dodge Sprinter Cargo Van 2009': 88,
'GMC Acadia SUV 2012': 121,
'Hyundai Genesis Sedan 2012': 137,
'Dodge Caliber Wagon 2012': 83,
'Jeep Liberty SUV 2012': 147,
'Mercedes-Benz 300-Class Convertible 1993': 161,
'Ford Expedition EL SUV 2009': 109,
'BMW 1 Series Coupe 2012': 28,
'Jaguar XK XKR 2012': 144,
'Hyundai Accent Sedan 2012': 136,
'Isuzu Ascender SUV 2008': 143,
'Nissan 240SX Coupe 1998': 171,
'Scion xD Hatchback 2012': 178,
'Chevrolet Corvette ZR1 2012': 56,
'Bentley Arnage Sedan 2009': 40,
'Chevrolet HHR SS 2010': 60,
'Land Rover LR2 SUV 2012': 155,
'Hyundai Azera Sedan 2012': 140,
'Chrysler Aspen SUV 2009': 76,
'Buick Regal GS 2012': 47,
'BMW 3 Series Wagon 2012': 30,
'Jeep Compass SUV 2012': 149,
'Ram C-V Cargo Van Minivan 2012': 174,
'Spyker C8 Convertible 2009': 179,
'Audi S4 Sedan 2007': 24,
'Rolls-Royce Ghost Sedan 2012': 176,
'AM General Hummer SUV 2000': 1,
'Ford Freestar Minivan 2007': 108,
'Bentley Mulsanne Sedan 2011': 41,
'Audi TT Hatchback 2011': 19,
'Mercedes-Benz SL-Class Coupe 2009': 163,
'Chevrolet Silverado 1500 Hybrid Crew Cab 2012': 54,
'Buick Enclave SUV 2012': 50,
'Chevrolet TrailBlazer SS 2009': 68,
'HUMMER H2 SUT Crew Cab 2009': 125,
'McLaren MP4-12C Coupe 2012': 160,
'Dodge Challenger SRT8 2011': 93,
'Suzuki SX4 Hatchback 2012': 183,
'Bugatti Veyron 16.4 Convertible 2009': 45,
'Toyota 4Runner SUV 2012': 189,
'Buick Rainier SUV 2007': 48,
'Chrysler Sebring Convertible 2010': 77,
'Acura Integra Type R 2001': 6,
'Audi V8 Sedan 1994': 16,
'Audi RS 4 Convertible 2008': 12,
'Honda Accord Coupe 2012': 128,
'Audi S4 Sedan 2012': 23,
'Aston Martin Virage Coupe 2012': 11,
'Chevrolet Sonic Sedan 2012': 63,
'Chevrolet Monte Carlo Coupe 2007': 72,
'Volvo XC90 SUV 2007': 195,
'Ford Mustang Convertible 2007': 107,
'Aston Martin Virage Convertible 2012': 10,
'smart fortwo Convertible 2012': 196,
'FIAT 500 Abarth 2012': 99,
'Infiniti G Coupe IPL 2012': 141,
'Dodge Caliber Wagon 2007': 84,
'Hyundai Tucson SUV 2012': 132,
'Acura ZDX Hatchback 2012': 7,
'BMW ActiveHybrid 5 Sedan 2012': 26,
'Ferrari California Convertible 2012': 102,
'Nissan Leaf Hatchback 2012': 168,
'Lamborghini Diablo Coupe 2001': 153,
'Audi S5 Convertible 2012': 21,
'BMW 6 Series Convertible 2007': 31,
'Ferrari 458 Italia Convertible 2012': 103,
'Chevrolet Silverado 2500HD Regular Cab 2012': 69,
'Chevrolet Corvette Convertible 2012': 55,
'Bugatti Veyron 16.4 Coupe 2009': 46,
'Tesla Model S Sedan 2012': 185,
'FIAT 500 Convertible 2012': 100,
'Hyundai Veloster Hatchback 2012': 130,
'Lincoln Town Car Sedan 2011': 156,
'Lamborghini Aventador Coupe 2012': 151,
'Dodge Ram Pickup 3500 Quad Cab 2009': 87,
'Nissan NV Passenger Van 2012': 169,
'Honda Odyssey Minivan 2007': 127,
'Maybach Landaulet Convertible 2012': 158,
'Chevrolet Silverado 1500 Regular Cab 2012': 75,
'Suzuki Kizashi Sedan 2012': 182,
'Chevrolet Tahoe Hybrid SUV 2012': 62,
'Mercedes-Benz Sprinter Van 2012': 166,
'Suzuki Aerio Sedan 2007': 181,
'Audi S5 Coupe 2012': 22,
'Aston Martin V8 Vantage Coupe 2012': 9,
'Chevrolet Malibu Hybrid Sedan 2010': 67,
'Ford F-150 Regular Cab 2012': 113,
'Ford Fiesta Sedan 2012': 117,
'Ford Focus Sedan 2007': 115,
'Bentley Continental Supersports Conv. Convertible 2012': 39,
'Chevrolet Silverado 1500 Classic Extended Cab 2007': 70,
'BMW X5 SUV 2007': 32,
'Jeep Wrangler SUV 2012': 146,
'Acura TL Type-S 2008': 4,
'Chrysler Crossfire Convertible 2008': 80,
'Lamborghini Gallardo LP 570-4 Superleggera 2012': 152,
'Mercedes-Benz E-Class Sedan 2012': 164,
'Chevrolet Express Cargo Van 2007': 64,
'GMC Terrain SUV 2012': 118,
'Dodge Magnum Wagon 2008': 92,
'Honda Accord Sedan 2012': 129,
'Chrysler PT Cruiser Convertible 2008': 81,
'Mazda Tribute SUV 2011': 159,
'BMW M3 Coupe 2012': 34,
'Eagle Talon Hatchback 1998': 98,
'Daewoo Nubira Wagon 2002': 82,
'BMW X6 SUV 2012': 33,
'Lamborghini Reventon Coupe 2008': 150,
'Cadillac SRX SUV 2012': 52,
'MINI Cooper Roadster Convertible 2012': 157,
'Acura RL Sedan 2012': 2,
'BMW 1 Series Convertible 2012': 27,
'Dodge Durango SUV 2007': 95,
'BMW M5 Sedan 2010': 35,
'Chrysler Town and Country Minivan 2012': 78}
def define_model(width, height):
model_input = Input(shape=(width, height, 3), name='image_input')
model_main = tf.keras.applications.inception_resnet_v2.InceptionResNetV2(include_top=False, weights='imagenet')(model_input)
model_dense1 = Flatten()(model_main)
model_dense2 = Dense(256, activation='relu')(model_dense1)
model_out = Dense(196, activation="softmax")(model_dense2)
model = Model(model_input, model_out)
optimizer = Adam(lr=0.00004, beta_1=0.9, beta_2=0.999)
model.compile(loss="categorical_crossentropy", optimizer=optimizer, metrics=["accuracy"])
return model
image_size = 224
def data_generator(df, batch_size=32):
while True:
image_nums = np.random.randint(0,df.shape[0], size=batch_size)
batch_images = np.zeros(shape=(batch_size, image_size, image_size, 3))
batch_labels = np.zeros(shape=(batch_size, len(num_classes)))
batch_bboxes = np.zeros(shape=(batch_size, 4))
for i in range(batch_size):
#Read and resize image
img = image.load_img(df.loc[image_nums[i], 'Path'], target_size=(image_size, image_size))
img_array = image.img_to_array(img)
#Update batch
batch_images[i] = img_array
#convert image classification label to one hot vector
cls_label = df.loc[image_nums[i], 'Class']
cls_label = to_categorical(cls_label - 1,num_classes=len(num_classes), dtype='float32')
batch_labels[i] = cls_label
#Read and resize bounding box co-ordinates
image_width = df.loc[image_nums[i], 'Width']
image_height = df.loc[image_nums[i], 'Height']
xmin = df.loc[image_nums[i], 'xmin'] * image_size/image_width
xmax = df.loc[image_nums[i], 'xmax'] * image_size/image_width
ymin = df.loc[image_nums[i], 'ymin'] * image_size/image_height
ymax = df.loc[image_nums[i], 'ymax'] * image_size/image_height
batch_bboxes[i] = [xmin, ymin, xmax-xmin, ymax-ymin]
#Normalize batch images
for i in range(batch_size):
batch_images[i] = batch_images[i]/255.0
batch_bboxes = batch_bboxes/image_size
#Return batch
yield batch_images, [batch_labels, batch_bboxes]
image_size = 256
target_size = (256, 256)
batch_size = 224
seed = 7
from tensorflow.keras.preprocessing import image
def build_data(data, batch_size):
index = np.random.randint(0,data.shape[0], size=batch_size)
train_images = np.zeros(shape=(batch_size, width, height, 3))
bounding_boxes = np.zeros(shape=(batch_size, 4))
class_labels = np.zeros(shape=(batch_size, len(num_classes)))
for i in range(batch_size):
path = data.loc[index[i], 'imagePath']
img = image.load_img(path, target_size=(width, height))
img_array = image.img_to_array(img)
train_images[i] = img_array
cls_label = data.loc[index[i], 'Image class']
cls_label = to_categorical(cls_label - 1,num_classes=len(num_classes), dtype='float32')
class_labels[i] = cls_label
#Normalizing bounding box co-ordinates
image_width = data.loc[index[i], 'width']
image_height = data.loc[index[i], 'height']
x1 = data.loc[index[i], 'X1'] * image_size/image_width
x2 = data.loc[index[i], 'X2'] * image_size/image_width
y1 = data.loc[index[i], 'Y1'] * image_size/image_height
y2 = data.loc[index[i], 'Y2'] * image_size/image_height
bounding_boxes[i] = [x1, y1, x2-x1, y2-y1]
#Normalizing batch images
for i in range(batch_size):
train_images[i] = train_images[i]/255.0
bounding_boxes = bounding_boxes/image_size
return train_images, [class_labels, bounding_boxes]
def define_generators(pathToTrainData):
train_datagen = tf.keras.preprocessing.image.ImageDataGenerator(
rotation_range=360,
width_shift_range=0.3,
height_shift_range=0.3,
shear_range=0.3,
zoom_range=0.5,
vertical_flip=True,
horizontal_flip=True,
validation_split=0.2
)
train_generator = train_datagen.flow_from_directory(
directory=pathToTrainData,
target_size=(width, height),
batch_size=batch_size,
color_mode='rgb',
class_mode="categorical",
subset='training',
classes=label_class_dict
)
validation_generator = train_datagen.flow_from_directory(
directory=pathToTrainData,
target_size=(width, height),
batch_size=batch_size,
color_mode='rgb',
class_mode="categorical",
subset='validation',
classes=label_class_dict
)
return train_generator, validation_generator
def define_callbacks():
es = EarlyStopping(monitor='loss', patience=5, mode='min', min_delta=0.0001)
checkpoint = ModelCheckpoint( filepath='car_inception_model.h5',
monitor='val_accuracy',
save_best_only=True,
verbose=1)
save_callback = [checkpoint,es]
return save_callback
inception_model = define_model(width, height)
inception_model.summary()
train_generator, validation_generator = define_generators(pathToTrainData)
save_callback = define_callbacks()
Model: "model_1" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= image_input (InputLayer) [(None, 256, 256, 3)] 0 _________________________________________________________________ inception_resnet_v2 (Functio (None, None, None, 1536) 54336736 _________________________________________________________________ flatten_1 (Flatten) (None, 55296) 0 _________________________________________________________________ dense_2 (Dense) (None, 256) 14156032 _________________________________________________________________ dense_3 (Dense) (None, 196) 50372 ================================================================= Total params: 68,543,140 Trainable params: 68,482,596 Non-trainable params: 60,544 _________________________________________________________________ Found 6598 images belonging to 196 classes. Found 1546 images belonging to 196 classes.
inception_model.fit(
train_generator,
epochs=nb_epoch,
steps_per_epoch=train_generator.samples // batch_size,
validation_data= validation_generator,
validation_steps=validation_generator.samples // batch_size,
callbacks=save_callback )
Epoch 1/20 21/21 [==============================] - 2497s 119s/step - loss: 5.2599 - accuracy: 0.0095 - val_loss: 5.2620 - val_accuracy: 0.0167 Epoch 00001: val_accuracy improved from 0.00533 to 0.01667, saving model to car_inception_model.h5 Epoch 2/20 21/21 [==============================] - 5487s 268s/step - loss: 5.2406 - accuracy: 0.0135 - val_loss: 5.2344 - val_accuracy: 0.0160 Epoch 00002: val_accuracy did not improve from 0.01667 Epoch 3/20 21/21 [==============================] - 2500s 120s/step - loss: 5.1996 - accuracy: 0.0151 - val_loss: 5.2067 - val_accuracy: 0.0107 Epoch 00003: val_accuracy did not improve from 0.01667 Epoch 4/20 21/21 [==============================] - 2508s 119s/step - loss: 5.1552 - accuracy: 0.0191 - val_loss: 5.1454 - val_accuracy: 0.0213 Epoch 00004: val_accuracy improved from 0.01667 to 0.02133, saving model to car_inception_model.h5 Epoch 5/20 21/21 [==============================] - 2485s 118s/step - loss: 5.0874 - accuracy: 0.0245 - val_loss: 5.0969 - val_accuracy: 0.0253 Epoch 00005: val_accuracy improved from 0.02133 to 0.02533, saving model to car_inception_model.h5 Epoch 6/20 21/21 [==============================] - 2437s 116s/step - loss: 5.0031 - accuracy: 0.0322 - val_loss: 5.0570 - val_accuracy: 0.0307 Epoch 00006: val_accuracy improved from 0.02533 to 0.03067, saving model to car_inception_model.h5 Epoch 7/20 21/21 [==============================] - 2395s 114s/step - loss: 4.9089 - accuracy: 0.0440 - val_loss: 4.9722 - val_accuracy: 0.0453 Epoch 00007: val_accuracy improved from 0.03067 to 0.04533, saving model to car_inception_model.h5 Epoch 8/20 21/21 [==============================] - 2398s 114s/step - loss: 4.7951 - accuracy: 0.0581 - val_loss: 4.9068 - val_accuracy: 0.0400 Epoch 00008: val_accuracy did not improve from 0.04533 Epoch 9/20 21/21 [==============================] - 2415s 115s/step - loss: 4.6224 - accuracy: 0.0751 - val_loss: 4.8754 - val_accuracy: 0.0487 Epoch 00009: val_accuracy improved from 0.04533 to 0.04867, saving model to car_inception_model.h5 Epoch 10/20 21/21 [==============================] - 19304s 960s/step - loss: 4.4491 - accuracy: 0.0956 - val_loss: 4.8338 - val_accuracy: 0.0587 Epoch 00010: val_accuracy improved from 0.04867 to 0.05867, saving model to car_inception_model.h5 Epoch 11/20 21/21 [==============================] - 1995s 95s/step - loss: 4.2326 - accuracy: 0.1273 - val_loss: 4.6225 - val_accuracy: 0.0827 Epoch 00011: val_accuracy improved from 0.05867 to 0.08267, saving model to car_inception_model.h5 Epoch 12/20 21/21 [==============================] - 2117s 101s/step - loss: 4.0178 - accuracy: 0.1505 - val_loss: 4.5087 - val_accuracy: 0.0973 Epoch 00012: val_accuracy improved from 0.08267 to 0.09733, saving model to car_inception_model.h5 Epoch 13/20 21/21 [==============================] - 2051s 98s/step - loss: 3.7566 - accuracy: 0.1828 - val_loss: 4.1818 - val_accuracy: 0.1480 Epoch 00013: val_accuracy improved from 0.09733 to 0.14800, saving model to car_inception_model.h5 Epoch 14/20 21/21 [==============================] - 2040s 97s/step - loss: 3.5199 - accuracy: 0.2218 - val_loss: 4.0375 - val_accuracy: 0.1673 Epoch 00014: val_accuracy improved from 0.14800 to 0.16733, saving model to car_inception_model.h5 Epoch 15/20 21/21 [==============================] - 2401s 115s/step - loss: 3.2723 - accuracy: 0.2580 - val_loss: 3.9339 - val_accuracy: 0.1927 Epoch 00015: val_accuracy improved from 0.16733 to 0.19267, saving model to car_inception_model.h5 Epoch 16/20 21/21 [==============================] - 2320s 110s/step - loss: 3.0279 - accuracy: 0.3022 - val_loss: 3.7990 - val_accuracy: 0.1893 Epoch 00016: val_accuracy did not improve from 0.19267 Epoch 17/20 21/21 [==============================] - 2302s 110s/step - loss: 2.8257 - accuracy: 0.3357 - val_loss: 3.6569 - val_accuracy: 0.2247 Epoch 00017: val_accuracy improved from 0.19267 to 0.22467, saving model to car_inception_model.h5 Epoch 18/20 21/21 [==============================] - 2481s 118s/step - loss: 2.6066 - accuracy: 0.3854 - val_loss: 3.4490 - val_accuracy: 0.2513 Epoch 00018: val_accuracy improved from 0.22467 to 0.25133, saving model to car_inception_model.h5 Epoch 19/20 21/21 [==============================] - 2270s 108s/step - loss: 2.4580 - accuracy: 0.4011 - val_loss: 3.3552 - val_accuracy: 0.2707 Epoch 00019: val_accuracy improved from 0.25133 to 0.27067, saving model to car_inception_model.h5 Epoch 20/20 13/21 [=================>............] - ETA: 1:06:32 - loss: 2.2895 - accuracy: 0.4497
from keras.models import load_model
classification_model = load_model('car_inception_model.h5')
classification_model.summary()
Model: "model_3" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= image_input (InputLayer) [(None, 256, 256, 3)] 0 _________________________________________________________________ inception_resnet_v2 (Functio (None, None, None, 1536) 54336736 _________________________________________________________________ flatten_11 (Flatten) (None, 55296) 0 _________________________________________________________________ dense_24 (Dense) (None, 256) 14156032 _________________________________________________________________ dense_25 (Dense) (None, 196) 50372 ================================================================= Total params: 68,543,140 Trainable params: 68,482,596 Non-trainable params: 60,544 _________________________________________________________________
test_path=car_test_image_details.iloc[0,:]['imagePath']
test_image = cv2.imread(test_path)
plt.imshow(test_image)
<matplotlib.image.AxesImage at 0x7fa64a290100>
test_image = cv2.resize(test_image, (256,256))
test_image_batch = np.expand_dims(test_image, axis=0)
test_image_prediction = classification_model.predict(test_image_batch)
test_image_prediction
array([[1.2779597e-03, 1.2676005e-03, 2.1965193e-06, 1.1230119e-03,
1.5071580e-04, 1.0937335e-04, 5.0878287e-03, 3.1894483e-04,
7.7284680e-04, 3.6158666e-03, 8.6485717e-04, 1.1032572e-02,
3.3310011e-02, 2.3274003e-02, 1.5984173e-04, 1.8023813e-04,
3.0008014e-02, 1.7210083e-05, 1.4729383e-05, 2.1756144e-04,
8.1819494e-04, 2.2711148e-04, 8.1172941e-04, 2.0693738e-05,
1.2514458e-02, 1.2631192e-05, 5.0312001e-04, 1.5530260e-05,
3.2503270e-03, 2.0493614e-03, 4.9151331e-03, 3.7755779e-06,
6.4883282e-04, 2.3743766e-04, 9.5265978e-06, 1.3939065e-03,
2.6780416e-03, 3.0689174e-04, 3.3540244e-05, 2.1045865e-04,
1.7572257e-03, 2.3340879e-04, 6.5650762e-05, 2.1548498e-04,
2.2343316e-03, 1.4816655e-04, 1.0772981e-03, 4.4044663e-04,
3.9031831e-05, 3.3770760e-07, 1.8840507e-04, 4.3658014e-02,
1.4143801e-04, 4.9988870e-03, 2.0048693e-04, 1.4442708e-03,
3.9919214e-03, 4.5615470e-05, 1.1948322e-02, 2.5380119e-03,
1.1095385e-01, 4.2818639e-05, 1.6468423e-03, 2.4252334e-03,
5.3910664e-03, 1.6003774e-03, 2.7224311e-04, 6.4031454e-05,
8.8208653e-05, 8.8530549e-05, 9.2350681e-05, 2.4369468e-03,
1.4656904e-06, 3.5433180e-04, 4.9890723e-04, 1.7919480e-04,
4.6559426e-04, 4.1411445e-03, 3.1596355e-06, 5.1913707e-04,
5.6655821e-03, 2.1081269e-03, 7.8586309e-04, 4.7475398e-03,
7.6645680e-02, 1.0143163e-03, 1.8915447e-04, 2.9784351e-05,
3.7633106e-03, 1.1924562e-04, 2.4714062e-03, 1.1484823e-04,
3.5401210e-03, 6.3059488e-03, 8.5613392e-05, 2.4214021e-05,
1.3049742e-03, 3.3784387e-04, 1.0948846e-04, 1.8505724e-04,
2.7016582e-05, 3.0836817e-03, 8.5593070e-05, 9.9187484e-05,
6.7287991e-05, 9.5505547e-03, 3.6088768e-05, 9.1127895e-06,
1.2969612e-01, 9.3973729e-05, 1.0345508e-03, 4.7292182e-05,
2.1732298e-05, 4.3882944e-02, 4.5566971e-04, 1.5266554e-04,
5.5894707e-05, 4.6271325e-05, 5.0833607e-03, 4.5796912e-04,
8.2210290e-06, 9.8792491e-03, 1.5172443e-02, 1.6044905e-04,
1.0675614e-03, 2.8162988e-04, 8.3932508e-04, 4.3457639e-03,
1.1339893e-05, 2.7954692e-03, 3.5988642e-03, 3.4556114e-03,
3.1591309e-04, 1.8991769e-06, 5.2343379e-03, 1.0151190e-05,
3.9382893e-04, 3.1967921e-04, 4.4183116e-04, 3.1833337e-03,
1.0528669e-03, 2.1728172e-05, 5.9256278e-04, 2.6445315e-04,
3.7377208e-04, 5.1721241e-03, 2.7460685e-06, 6.9010116e-07,
4.4059449e-05, 8.9970723e-05, 2.5567617e-05, 3.9161692e-05,
1.0132001e-04, 7.7786506e-03, 3.2352275e-06, 4.7456679e-06,
2.9375375e-04, 1.8132776e-02, 1.3748248e-04, 2.1309903e-05,
6.3660648e-04, 8.3476174e-05, 1.8924450e-04, 1.6542150e-02,
1.8817550e-03, 6.4680830e-04, 4.1264869e-02, 2.7671203e-06,
5.3738756e-04, 1.8016117e-02, 2.8527065e-03, 2.5489149e-04,
2.1120539e-04, 7.0547912e-06, 5.1251529e-03, 1.7736910e-03,
2.9762161e-06, 1.0033500e-03, 2.3141722e-05, 4.8442569e-05,
1.6143693e-02, 1.2140101e-02, 1.8698856e-03, 1.3245249e-04,
2.1345834e-03, 1.0308880e-04, 6.0362544e-02, 1.5721992e-03,
1.3475301e-04, 3.9441667e-02, 1.0241467e-04, 2.1987094e-02,
4.3851134e-04, 1.4106979e-04, 3.5265144e-03, 9.3625039e-03]],
dtype=float32)
np.argmax(test_image_prediction)
108
car_test_image_details
| Image Name | imagePath | class | height | width | X1 | Y1 | X2 | Y2 | Image class | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 00001.jpg | Dataset/Car Images/Test Images/Suzuki Aerio Se... | Suzuki Aerio Sedan 2007 | 182 | 276 | 30 | 52 | 246 | 147 | 181 |
| 1 | 00002.jpg | Dataset/Car Images/Test Images/Ferrari 458 Ita... | Ferrari 458 Italia Convertible 2012 | 360 | 640 | 100 | 19 | 576 | 203 | 103 |
| 2 | 00003.jpg | Dataset/Car Images/Test Images/Jeep Patriot SU... | Jeep Patriot SUV 2012 | 741 | 1024 | 51 | 105 | 968 | 659 | 145 |
| 3 | 00004.jpg | Dataset/Car Images/Test Images/Toyota Camry Se... | Toyota Camry Sedan 2012 | 480 | 640 | 67 | 84 | 581 | 407 | 187 |
| 4 | 00005.jpg | Dataset/Car Images/Test Images/Tesla Model S S... | Tesla Model S Sedan 2012 | 373 | 600 | 140 | 151 | 593 | 339 | 185 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 8036 | 08037.jpg | Dataset/Car Images/Test Images/Chevrolet Sonic... | Chevrolet Sonic Sedan 2012 | 800 | 1200 | 49 | 57 | 1169 | 669 | 63 |
| 8037 | 08038.jpg | Dataset/Car Images/Test Images/Audi V8 Sedan 1... | Audi V8 Sedan 1994 | 480 | 640 | 23 | 18 | 640 | 459 | 16 |
| 8038 | 08039.jpg | Dataset/Car Images/Test Images/Audi 100 Sedan ... | Audi 100 Sedan 1994 | 303 | 635 | 33 | 27 | 602 | 252 | 17 |
| 8039 | 08040.jpg | Dataset/Car Images/Test Images/BMW Z4 Converti... | BMW Z4 Convertible 2012 | 427 | 640 | 33 | 142 | 521 | 376 | 38 |
| 8040 | 08041.jpg | Dataset/Car Images/Test Images/BMW X5 SUV 2007... | BMW X5 SUV 2007 | 426 | 640 | 77 | 73 | 506 | 380 | 32 |
8041 rows × 10 columns
Here we can see that image class is coming as 108, but actual one is 181. Let us try with some more test images
def predict_image_class(test_path):
image = cv2.imread(test_path)
image = cv2.resize(image, (256,256))
test_image_batch = np.expand_dims(image, axis=0)
test_image_prediction = classification_model.predict(test_image_batch)
return np.argmax(test_image_prediction)
test_path=car_test_image_details.iloc[1,:]['imagePath']
test_image = cv2.imread(test_path)
plt.imshow(test_image)
<matplotlib.image.AxesImage at 0x7fa67d9267f0>
predict_image_class(test_path)
141
car_test_image_details['Predicted_Image_class']= car_test_image_details['imagePath'].apply(lambda x:predict_image_class(x))
car_test_image_details
| Image Name | imagePath | class | height | width | X1 | Y1 | X2 | Y2 | Image class | Predicted_Image_class | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 00001.jpg | Dataset/Car Images/Test Images/Suzuki Aerio Se... | Suzuki Aerio Sedan 2007 | 182 | 276 | 30 | 52 | 246 | 147 | 181 | 108 |
| 1 | 00002.jpg | Dataset/Car Images/Test Images/Ferrari 458 Ita... | Ferrari 458 Italia Convertible 2012 | 360 | 640 | 100 | 19 | 576 | 203 | 103 | 141 |
| 2 | 00003.jpg | Dataset/Car Images/Test Images/Jeep Patriot SU... | Jeep Patriot SUV 2012 | 741 | 1024 | 51 | 105 | 968 | 659 | 145 | 68 |
| 3 | 00004.jpg | Dataset/Car Images/Test Images/Toyota Camry Se... | Toyota Camry Sedan 2012 | 480 | 640 | 67 | 84 | 581 | 407 | 187 | 152 |
| 4 | 00005.jpg | Dataset/Car Images/Test Images/Tesla Model S S... | Tesla Model S Sedan 2012 | 373 | 600 | 140 | 151 | 593 | 339 | 185 | 150 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 8036 | 08037.jpg | Dataset/Car Images/Test Images/Chevrolet Sonic... | Chevrolet Sonic Sedan 2012 | 800 | 1200 | 49 | 57 | 1169 | 669 | 63 | 41 |
| 8037 | 08038.jpg | Dataset/Car Images/Test Images/Audi V8 Sedan 1... | Audi V8 Sedan 1994 | 480 | 640 | 23 | 18 | 640 | 459 | 16 | 92 |
| 8038 | 08039.jpg | Dataset/Car Images/Test Images/Audi 100 Sedan ... | Audi 100 Sedan 1994 | 303 | 635 | 33 | 27 | 602 | 252 | 17 | 69 |
| 8039 | 08040.jpg | Dataset/Car Images/Test Images/BMW Z4 Converti... | BMW Z4 Convertible 2012 | 427 | 640 | 33 | 142 | 521 | 376 | 38 | 20 |
| 8040 | 08041.jpg | Dataset/Car Images/Test Images/BMW X5 SUV 2007... | BMW X5 SUV 2007 | 426 | 640 | 77 | 73 | 506 | 380 | 32 | 187 |
8041 rows × 11 columns
car_test_image_details.iloc[11,:]
Image Name 00012.jpg imagePath Dataset/Car Images/Test Images/Ford Freestar M... class Ford Freestar Minivan 2007 height 194 width 259 X1 14 Y1 21 X2 242 Y2 156 Image class 108 Predicted_Image_class 108 Name: 11, dtype: object
np.where(car_test_image_details['Image class'] == car_test_image_details['Predicted_Image_class'])
(array([ 11, 395, 530, 536, 554, 769, 1108, 1389, 1641, 1780, 1946,
2001, 2005, 2071, 2251, 2318, 2351, 2482, 2504, 3098, 3140, 3141,
3203, 3222, 3286, 3461, 3595, 3679, 3773, 3825, 3833, 4135, 4156,
4199, 4221, 4222, 4256, 4291, 4307, 4467, 4629, 4633, 4935, 5078,
5262, 5335, 5345, 5401, 5483, 5598, 5644, 5882, 6090, 6103, 6112,
6151, 6201, 6248, 6296, 6353, 6381, 6383, 6450, 6561, 6582, 6678,
6736, 6751, 6812, 6828, 7284, 7331, 7391, 7509, 7672, 7705, 7710,
7725, 7726, 7921]),)
We can see that only above rows got predicted correctly. This CNN model is not performing accuratly. We will try with another model now.
def define_model(width, height):
model_input = Input(shape=(width, height, 3), name='image_input')
model_main = tf.keras.applications.inception_resnet_v2.InceptionResNetV2(include_top=False, weights='imagenet')(model_input)
model_dense1 = Flatten()(model_main)
model_dense2 = Dense(256, activation='relu')(model_dense1)
#model_out = Dense(196, activation="softmax")(model_dense2)
#Classification
class_output = Dense(len(num_classes), activation='softmax',name='class')
#Regression
reg_output = Dense(4,activation='sigmoid',name='reg')
#with classification and regression
model_out = [class_output,reg_output]
model = Model(model_input, model_out)
optimizer = Adam(lr=0.00004, beta_1=0.9, beta_2=0.999)
model.compile(loss="categorical_crossentropy", optimizer=optimizer, metrics=["accuracy"])
return model
train_generator = build_train_data(car_train_image_details, batch_size=batch_size)
train_generator
(array([[[[0.42745098, 0.42745098, 0.42745098],
[0.42745098, 0.42745098, 0.42745098],
[0.42745098, 0.42745098, 0.42745098],
...,
[0.77254902, 0.77254902, 0.77254902],
[0.77647059, 0.77647059, 0.77647059],
[0.77647059, 0.77647059, 0.77647059]],
[[0.42745098, 0.42745098, 0.42745098],
[0.42745098, 0.42745098, 0.42745098],
[0.42745098, 0.42745098, 0.42745098],
...,
[0.77254902, 0.77254902, 0.77254902],
[0.77647059, 0.77647059, 0.77647059],
[0.77647059, 0.77647059, 0.77647059]],
[[0.42745098, 0.42745098, 0.42745098],
[0.42745098, 0.42745098, 0.42745098],
[0.42745098, 0.42745098, 0.42745098],
...,
[0.77254902, 0.77254902, 0.77254902],
[0.77647059, 0.77647059, 0.77647059],
[0.77647059, 0.77647059, 0.77647059]],
...,
[[0.83921569, 0.83921569, 0.83921569],
[0.83921569, 0.83921569, 0.83921569],
[0.83921569, 0.83921569, 0.83921569],
...,
[0.83921569, 0.84705882, 0.84313725],
[0.83921569, 0.84705882, 0.84313725],
[0.83529412, 0.84313725, 0.83921569]],
[[0.83921569, 0.83921569, 0.83921569],
[0.83921569, 0.83921569, 0.83921569],
[0.83921569, 0.83921569, 0.83921569],
...,
[0.83921569, 0.84705882, 0.84313725],
[0.83921569, 0.84705882, 0.84313725],
[0.83529412, 0.84313725, 0.83921569]],
[[0.83921569, 0.83921569, 0.83921569],
[0.83921569, 0.83921569, 0.83921569],
[0.83921569, 0.83921569, 0.83921569],
...,
[0.83921569, 0.84705882, 0.84313725],
[0.83921569, 0.84705882, 0.84313725],
[0.83529412, 0.84313725, 0.83921569]]],
[[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
...,
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]]],
[[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
...,
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]]],
...,
[[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
...,
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]]],
[[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
...,
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]]],
[[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
...,
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]],
[[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ],
...,
[0. , 0. , 0. ],
[0. , 0. , 0. ],
[0. , 0. , 0. ]]]]),
[array([[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]]),
array([[0.01532567, 0.06060606, 0.98467433, 0.93939394],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ]])])
test_generator = build_train_data(car_test_image_details, batch_size=batch_size)
test_generator
(array([[[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
...,
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]]],
[[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
...,
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]]],
[[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
...,
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]]],
...,
[[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
...,
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]]],
[[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
...,
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]]],
[[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
...,
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]],
[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
...,
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]]]]),
[array([[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]]),
array([[0.33375 , 0.64090481, 0.256875 , 0.23468426],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. ]])])
# inception_model_2 = define_model(width, height)
# inception_model.summary()
# save_callback = define_callbacks()
train_generator = data_generator(train, batch_size=batchsize)
train = data_generator(car_train_image_details, batch_size=batch_size)
train
<generator object data_generator at 0x7fa6772be5f0>